• Sign in to Neowin Faster!

    Create an account on Neowin to contribute and support the site.

  • 0
Sign in to follow this  

htaccess rewrite

Question

Richard Grant    7

I have this: (works)

#RewriteCond %{REQUEST_URI} ([a-zA-Z0-9]+)
RewriteRule ([a-zA-Z0-9]+) folder/file.php [L]

 

I want this: (doesnt work)

#RewriteCond %{REQUEST_URI} ([a-zA-Z0-9]+)
RewriteRule ([a-zA-Z0-9]+) folder/$1.php [L]

I would like $1 to equal the matched expression ([a-zA-Z0-9]+)

 

 

 

Extra information:

http://mysite.com/file.php rewrites the url to http://mysite.com/file

Share this post


Link to post
Share on other sites

4 answers to this question

Recommended Posts

  • 0
+virtorio    3,121

Try putting this above your rule.

 

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

Share this post


Link to post
Share on other sites
  • 0
Richard Grant    7

Reserved.

Share this post


Link to post
Share on other sites
  • 0
Richard Grant    7

 

Try putting this above your rule.

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

 

It worked!

 

Do you mind telling me what is happening there

Overall i am confused how Rewritecond works

Share this post


Link to post
Share on other sites
  • 0
+virtorio    3,121

It worked!

 

Do you mind telling me what is happening there

Overall i am confused how Rewritecond works

It stops rewriting as soon as the request URI points to a file or directory name that exists on the server. Without it, the rewritten string will forever get matched and rewritten again, causing an infinite loop.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.