Jump to content

mod_rewrite problem


conormacaoidh

Recommended Posts

Hi,

 

Can anyone see anything wrong with this:

 

RewriteEngine on

 

RewriteCond %{SCRIPT_NAME} !\.php

RewriteRule ^cp[/]*?$ _cp/$1 [L]

RewriteRule ^css/(.*)$ /_inc/css/$1 [L]

RewriteRule ^js/(.*)$ /_inc/js/$1 [L]

RewriteRule ^img/(.*)$ /_inc/img/$1 [L]

RewriteRule ^files/(.*)$ /_user/files/$1 [L]

RewriteRule ^(.*)$ index.php?page=$1 [L,QSA]

 

In this case only the last rule works. When I comment out the last rule then all of the other rules work!

 

I don't know what is happening....

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/172167-mod_rewrite-problem/
Share on other sites

  • 2 weeks later...

I think that you need to stop the last one from happening to the requests that you have already changed. Even though you specified Last, the .htaccess file is reprocessed for each sub directory(I think)

 

 

so:


RewriteCond %{SCRIPT_NAME} !\.php
RewriteRule ^cp[/]*?$ _cp/$1 [L]
RewriteRule ^css/(.*)$ /_inc/css/$1 [L]
RewriteRule ^js/(.*)$ /_inc/js/$1 [L]
RewriteRule ^img/(.*)$ /_inc/img/$1 [L]
RewriteRule ^files/(.*)$ /_user/files/$1 [L]
RewriteCond $1 !^(_cp/|/_inc/css/|/_inc/js/|/_inc/img/|/_user/files/)
RewriteRule ^(.*)$ index.php?page=$1 [L,QSA]

 

Also, if you want that first RewriteCond to stop all php requests then you may want add a rule to skip the next 5 RewriteRules.

 


RewriteCond %{SCRIPT_NAME} !\.php
RewriteRule - [s=5]
RewriteRule ^cp[/]*?$ _cp/$1 [L]
RewriteRule ^css/(.*)$ /_inc/css/$1 [L]
RewriteRule ^js/(.*)$ /_inc/js/$1 [L]
RewriteRule ^img/(.*)$ /_inc/img/$1 [L]
RewriteRule ^files/(.*)$ /_user/files/$1 [L]
RewriteCond $1 !^(_cp/|/_inc/css/|/_inc/js/|/_inc/img/|/_user/files/)
RewriteRule ^(.*)$ index.php?page=$1 [L,QSA]

 

Link to comment
https://forums.phpfreaks.com/topic/172167-mod_rewrite-problem/#findComment-916862
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.