SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Feb 2013
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Simple rewrite question

    basically what I am trying to do is rewrite localhost/app/test/create.php to localhost/app/test/create/ which I am capable of doing with the last line of my htaccess but it's not working for me. So obviously I missing something important here


    So my htaccess looks like this.

    Code:
    RewriteEngine On
    RewriteBase /app/
    RewriteRule ^index\.php(.*)$ $1 [R,L,QSA]
    RewriteRule ^(.*)/index\.php$ $1/ [R,L]
    //this next line does kind of what I want to do... but I get Not Found instead of the page being served.
    RewriteRule ^(.*)/(.*)\.php$ $1/$2/ [R,L]

  2. #2
    SitePoint Addict deadmix's Avatar
    Join Date
    Jun 2009
    Location
    france
    Posts
    210
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Try this code :

    Code:
    RewriteEngine On
    
    # Unless directory, remove trailing slash
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^([^/]+)/$ localhost/app/test/create/$1 [R=301,L]
    
    # Redirect external .php requests to extensionless url
    RewriteCond %{THE_REQUEST} ^(.+)\.php([#?][^\ ]*)?\ HTTP/
    RewriteRule ^(.+)\.php$ localhost/app/test/$1 [R=301,L]
    
    # Resolve .php file for extensionless php urls
    RewriteRule ^([^/.]+)$ $1.php [L]

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

    You're going in the wrong direction! YOU must create the non-servable URI then write mod_rewrite code to redirect to something Apache can serve.

    You might benefit from reading the mod_rewrite tutorial linked in my signature as it contains explanations and sample code. It's helped may members and should help you, too.

    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

  4. #4
    SitePoint Member
    Join Date
    Feb 2013
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by dklynn View Post
    rob,

    You're going in the wrong direction! YOU must create the non-servable URI then write mod_rewrite code to redirect to something Apache can serve.

    You might benefit from reading the mod_rewrite tutorial linked in my signature as it contains explanations and sample code. It's helped may members and should help you, too.

    Regards,

    DK
    Wow, thanks a ton. Your site brings nostalgic memories of the 90's I love it.

  5. #5
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,680
    Mentioned
    20 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by robawtic View Post
    Wow, thanks a ton. Your site brings nostalgic memories of the 90's I love it.
    Rob,

    I'll assume that means that the page is too long. I know that (and I'm always trying to prevent the necessity of scrolling) but that was done in case someone wanted to download the whole enchalada (I hate docs spread over many pages).

    In any event, I hope it helped.

    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
  •