Got more questions? Find advice on: ASP | SQL | XML | Windows
in Search
Welcome to RegexAdvice Sign in | Join | Help

Pretty URLs not working

Last post 04-28-2008, 12:51 PM by calrockx. 2 replies.
Sort Posts: Previous Next
  •  04-28-2008, 4:22 AM 41670

    Pretty URLs not working

    Hello, I'm totally new to using RegEx, but was able to successfully implement some "pretty urls" rewriting (http://www.roscripts.com/Pretty_URLs_-_a_guide_to_URL_rewriting-168.html) using RegEx.  But on another section of my website, eh...not so successful.

     

    I've got a section on my site that connects to a database to pull up some info on some projects.  So for example, one page might look like this:

    http://charlesrubinoff.com/work/?type=print&Id=optimism

    where the variables TYPE and ID are in the url to pull up the appropriate resulting info.   So, the mod_rewrite stuff I put into the .htaccess is as follows:

    RewriteEngine on
    RewriteRule ^([^/\.]+)/?([^/\.]+)*/?$ index.php?type=$1&id=$2[NC,L]


    so, for the example above, i should be able to enter http://charlesrubinoff.com/work/print/optimism and it'd pull  up the same page as http://charlesrubinoff.com/work/?type=print&Id=optimism, right?  well, it does.... kind of.

    the first variable (type) and second (id) will always be some text strings, possibly involving numbers.  i admit, the rewriterule i have above is based on a google search, not me fully understanding how to write regex. 

     

    a page comes up, but the images and project-specific info doesn't show.  the images linked to the database don't show, but also just a static image i have on that particular index.php doesn't show.    and if i just use the first variable, say http://charlesrubinoff.com/work/print, that works but not when i add the second, as in http://charlesrubinoff.com/work/print/optimism

    i think it's just a matter of me coding the regex wrong, but hmm..... any ideas?

    the above regex i'm using in another section (the About section on my site) and it works perfectly.   

    Filed under: , ,
  •  04-28-2008, 12:20 PM 41687 in reply to 41670

    Re: Pretty URLs not working

    http://charlesrubinoff.com/work/print/optimism to http://charlesrubinoff.com/work/?type=print&Id=optimism

    RewriteEngine ON

    RewriteRule /?work/([^/]+)/([^/]+)$ /index.php?type=$1&Id=$2 [L]

    if the .htaccess is put in the DocumentRoot of your charlesrubinoff.com vhost.

     

     

  •  04-28-2008, 12:51 PM 41694 in reply to 41687

    Re: Pretty URLs not working

    ooh

    that almost works Smile

     i did add the work directory to the second half of the rule..

    RewriteEngine ON
    RewriteRule /?work/([^/]+)/([^/]+)$ /work/index.php?type=$1&Id=$2 [L]

     

     going to a page like http://charlesrubinoff.com/work/print/yota_mag works to bring up what would normally be http://charlesrubinoff.com/work/?type=print&Id=yota_mag, it brings up the correct project info, but not of the corresponding images

    at the end of this page i'm working on, index.php, i added <img src="flag-day.jpg" />, a simple static image to the page, and it doesn't work either when using pretty URLs

    so what you gave me works, except images.  hmmm....any idea? 

     

     

    ***EDIT***

    well, it looks like relative paths worked normally, but with the pretty urls, i had to set the image paths to refer to the root, and not they work. yay.

    anyway man, thanks for your help. Smile 

View as RSS news feed in XML