Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Simple question really.

After an internal redirect, the original 'context' is gone. I'd like to know if there is a variable or flag that allows me to check against the original request instead of the rewritten request. Pseudo code:

 RewriteCond %{REQUEST_FILENAME} !-f 
 RewriteRule .+ public/$0.html [L]

 RewriteCond %{WHAT_USER_TYPED} ^public/(.+)\.html
 RewriteRule .+ - [R=404,L]

In this example, when I type mywebsite.com/slug the request gets rewritten to path public/slug.html. Now, an internal redirect occurs and my path might match the second condition public/(.+)\.html, and returns a 404. That's not what I want. So, I'd like to know if there is some kind of solution to this.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

Yet another reason why you should avoid adding rewriterules in .htaccess files. If you would do this in the main server context you would not have this problem. In a directory context or .htaccess file each rewrite causes an internal subrequest.

There is a parameter that contains the original request, It's "%{THE_REQUEST}

RewriteCond %{REQUEST_FILENAME}    !-f
RewriteRule (.*)                   public/$0.html?redir [L]

RewriteCond %{THE_REQUEST}        GET\ /public
RewriteRule .*                    - [R=404,L]

This should do it.

share|improve this answer
    
Thanks, that solves it! Good tip on the difference between htaccess files and server config. I chose .htaccess since this problem was on a shared hosting server, but I may want to reconsider. –  Phortuin Apr 9 '13 at 10:48

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.