www.webdeveloper.com
Results 1 to 8 of 8

Thread: Apache mod_rewrite help

  1. #1
    Join Date
    Feb 2012
    Posts
    102

    Apache mod_rewrite help

    Hi everyone,

    I couldnt find a forum on this specifically so I thought I would ask in the php forum. I am looking to re-write my urls from

    Code:
    http://www.example.com/page.php?id=119
    to

    Code:
    http://www.example.com/page/119
    If anyone can help me out with the code to accomplish this that would be great. I have been reading about it all day and I cant seem to get it straight.
    Owner of Reality TV Addict
    Publisher of Strategies for Stretching Your Income (ebook)
    CEO and Founder of Sport Directions
    Follow me at @RealityTV_Forum

  2. #2
    Join Date
    Mar 2011
    Posts
    1,133
    I'm no .htaccess expert, but I've used a variation on the code below:
    Code:
    RewriteCond %{REQUEST_URI} ^/page/(\d+)$
    RewriteRule ^/page/(\d+)$ /page.php?id=$1 [L]
    I didn't test this code, so you may well have to modify it. You can also try searching on "htaccess search engine friendly URLs" to find alternatives.
    Rick Trethewey
    Rainbo Design

  3. #3
    Join Date
    Feb 2012
    Posts
    102
    Thanks for the reply but for some reason I still can not get it to work. I got it to say
    Code:
    http://www.example.com/page/?id=119
    but that is not right and returns an error.
    Owner of Reality TV Addict
    Publisher of Strategies for Stretching Your Income (ebook)
    CEO and Founder of Sport Directions
    Follow me at @RealityTV_Forum

  4. #4
    Join Date
    Mar 2011
    Posts
    1,133
    I'm not sure if you understood my message. The code I posted goes in the .htaccess file in the root directory of your website. Did you do that?
    Rick Trethewey
    Rainbo Design

  5. #5
    Join Date
    Feb 2012
    Posts
    102
    Yes that is how you do mod_rewrite. My redirects work fine but the url changes dont seem to work.
    Owner of Reality TV Addict
    Publisher of Strategies for Stretching Your Income (ebook)
    CEO and Founder of Sport Directions
    Follow me at @RealityTV_Forum

  6. #6
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    2,206
    You could always try looking on the Apache website.

    I have tried to decipher what they say but its as clear as mud.

    http://httpd.apache.org/docs/2.0/misc/rewriteguide.html
    Yes, I know I'm about as subtle as being hit by a bus..(\\.\ Aug08)
    Yep... I say it like I see it, even if it is like a baseball bat in the nutz... (\\.\ Aug08)
    I want to leave this world the same way I came into it, Screaming, Incontinent & No memory!
    I laughed that hard I burst my colostomy bag... (\\.\ May03)
    Life for some is like a car accident... Mine is like a motorway pile up...

    Problems with Vista? :: Getting Cryptic wid it. :: The 'C' word! :: Whois?

  7. #7
    Join Date
    Jul 2013
    Posts
    29
    Probably you mixed rewrite and redirect
    Rewrite is when you enter "some.url/page/112" into browser address bar and the script is invoked as it was requested as "some.url/page.php?id=112"
    Redirect is when you enter "some.url/page.php?id=112" into browser address bar and the browser is redirected to "some.url/page/112"
    Which one do you need?

  8. #8
    Join Date
    Jul 2013
    Posts
    31
    I'm not sure, but this should work. Check it out...
    Code:
    RewriteEngine On
    RewriteRule ^page/([0-9]+)$ page.php?id=$1 [L]
    Or if its in a folder, it should be :
    Code:
    RewriteEngine On
    RewriteRule ^folder/page/([0-9]+)$ folder/page.php?id=$1 [L]

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles