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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.