SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2009
    Location
    Porto,Portugal
    Posts
    76
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    simple mod_rewrite help

    Hi.
    My website have a url like this: www.example.com/index.php?p=pagename.
    I want to rewrite the url to www.example.com/pagename.

    I have made this but doesn´t work.
    RewriteEngine on
    RewriteRule ^/([a-zA-Z_]+)$ index.php?p=$1 [L]

  2. #2
    SitePoint Evangelist BJ Duncan's Avatar
    Join Date
    Jun 2007
    Location
    North Richmond
    Posts
    495
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey Popovich88 - you were oh so close, just add the ? character.

    RewriteEngine on
    RewriteRule ^/?([a-zA-Z]+)$ index.php?p=$1 [L]

    Code .htaccess:
    RewriteEngine on
    RewriteRule ^/?([a-zA-Z]+)$ index.php?p=$1 [L]
    Regards,
    BJ Duncan

  3. #3
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,692
    Mentioned
    20 Post(s)
    Tagged
    3 Thread(s)
    popo,

    The reason for the ? is that Apache 1.x requires the leading / after the start anchor but Apache 2.x believes it's already there so it rejects a "hard" /. Making the leading slash (after the start anchor) makes the code acceptable to both flavors of Apache.

    ^/ => Apache 1.x
    ^ => Apache 2.x
    ^/? => work for both!

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator


Bookmarks

Posting Permissions

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