Forum Moderators: phranque

Message Too Old, No Replies

ReWrite URL Not Ending With [L]

         

boxfan

8:57 pm on Jan 28, 2008 (gmt 0)

10+ Year Member



Hello,

I have the following rules

RewriteRule ^/some_directory/some_file(.*)$ http://www.example.com/some_directory/some_file.php [L,R=301]

RewriteCond $1 !^a_directory
RewriteCond $1 !^another_directory
RewriteRule ^(.*)$ http://www.example.com [L,R=301]

My problem is the first rule is not working. The url http://www.example.com/some_directory/some_file is redirecting to the home page.

I was under the impression that the first rule would be executed and then no other rules would be followed after that with [L] flag?

So, I want the first rule followed and then stop looking at any other rules.

Thanks,

[edited by: jdMorgan at 10:23 pm (utc) on Jan. 28, 2008]
[edit reason] example.com [/edit]

jdMorgan

10:12 pm on Jan 28, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you code is in .htaccess (as implied by the form of the second rule), the leading slash (actually, the entire path to the current .htaccess file's directory) will be stripped out, as documented. Therefore, you first rule will never match with a leading slash in the pattern as shown.

[added] Also note that parentheses are not required in your first rule, and that your second rule should have a trailing slash on the substitution URL in order to prevent a second redirect occurring as a result of the action of mod_dir. [/added]

Jim

[edited by: jdMorgan at 10:25 pm (utc) on Jan. 28, 2008]

boxfan

4:22 pm on Jan 31, 2008 (gmt 0)

10+ Year Member



Thank you for the information.

I'm having a problem with this code now in .htaccess

RewriteCond $1!^customers
RewriteCond $1!^crons
RewriteCond $1!^fulfillment
RewriteCond $1!^cgi-bin
RewriteCond $1!^CommConfig
RewriteCond $1!^affiliates
RewriteRule ^(.*)$ [mydomain.com...] [L,R=301]

Only the first conditional statement is being followed. Trying to access any of the directories past the first conditional statement redirects me to mydomain.com.

boxfan

6:36 pm on Jan 31, 2008 (gmt 0)

10+ Year Member



Nevermind, found this

rewriteRule ^(imagedirĶimagedir2Ķimagedir3) - [L]

Thanks.