• 0

htaccess rewrite


Go to solution Solved by virtorio,

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

Link to post
Share on other sites

4 answers to this question

Recommended Posts

  • 0
+virtorio    3,329

Try putting this above your rule.

 

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
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

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

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.

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
  • Recently Browsing   0 members

    No registered users viewing this page.