1

So I have this rule in my .htaccess file. It correctly stops the rewrite for the "files" directory but none of the other directories. I expected this to not redirect the files, pdf, img, and account directories.

RewriteCond %{REQUEST_URI} !^/(files|pdf|img|account).*$ [NC]

I also tried it with

RewriteCond %{REQUEST_URI} ^/[^(files|pdf|img|account)].*$ [NC]

This stops the redirecting for the all the requested directories but also for the mobile site so I think this just breaks the whole rule set I have.

My rule set is kind of long it so for redirecting from our main site to m.mainsite for mobile devices. If it'd be useful to see the whole set please let me know.

Thanks.

2 Answers 2

1

Instead of REQUEST_URI try THE_REQUEST variable as THE_REQUEST variable represents original request received by Apache from your browser and it doesn't get overwritten after execution of some rewrite rules.

RewriteCond %{THE_REQUEST} !/(files|pdf|img|account) [NC]
Sign up to request clarification or add additional context in comments.

2 Comments

Yup, just swapping it to the_request has it functioning correctly. Thanks. Is there a way to output the different server variables for debugging in the future?
Yes in php code you can use: <? phpinfo(); ?> in PHP code to output various variables.
0

You can use these two condition statements instead of just the one. One for the directory and then one for anything inside the directory such as a file or another directory.

RewriteCond %{REQUEST_URI} !^/(files|pdf|img|account)/?$ [NC]
RewriteCond %{REQUEST_URI} !^/(files|pdf|img|account)/(.*)$ [NC]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.