Forum Moderators: phranque
AddDefaultCharset UTF-8
Options +FollowSymLinks
RewriteEngine on
ErrorDocument 404 /error404.php
RewriteCond %{REQUEST_URI} ^/cms/inc/menu\.php$ [OR]
RewriteCond %{REQUEST_URI} ^/cms/inc/inmenu\.txt$ [OR]
RewriteCond %{REQUEST_URI} ^/cms/admin/list\.php$ [OR]
RewriteCond %{REQUEST_URI} ^/cms/([A-Za-z0-9_-]+)\.txt$ [OR]
RewriteCond %{REQUEST_URI} ^/cms/comments/([A-Za-z0-9_-]+)\.txt$ [OR]
RewriteCond %{REQUEST_URI} ^/img/$
RewriteRule .* - [F]
RewriteCond %{REQUEST_URI} ^/cms/$
RewriteRule ^cms/$ / [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /cms/([A-Za-z0-9_-]+)\.php\ HTTP/
RewriteRule ^cms/([A-Za-z0-9_-]+)\.php$ /$1 [R=301,L]
RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^$ /cms/index.php [L]
RewriteCond %{REQUEST_URI} !^/index$
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([A-Za-z0-9_-]+)\ HTTP/
RewriteRule ^([A-Za-z0-9_-]+)$ /cms/$1.php [L]
AddDefaultCharset UTF-8
ErrorDocument 404 /error404.php
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/blah/cms/inc/menu\.php$ [OR]
RewriteCond %{REQUEST_URI} ^/blah/cms/inc/inmenu\.txt$ [OR]
RewriteCond %{REQUEST_URI} ^/blah/cms/admin/list\.php$ [OR]
RewriteCond %{REQUEST_URI} ^/blah/cms/([A-Za-z0-9_-]+)\.txt$ [OR]
RewriteCond %{REQUEST_URI} ^/blah/cms/comments/([A-Za-z0-9_-]+)\.txt$ [OR]
RewriteCond %{REQUEST_URI} ^/blah/img/$
RewriteRule .* - [F]
RewriteCond %{REQUEST_URI} ^/blah/cms/$
RewriteRule ^cms/$ /blah/ [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /blah/cms/([A-Za-z0-9_-]+)\.php\ HTTP/
RewriteRule ^cms/([A-Za-z0-9_-]+)\.php$ /blah/$1 [R=301,L]
RewriteCond %{REQUEST_URI} ^/blah/$
RewriteRule ^$ /blah/cms/index.php [L]
RewriteCond %{REQUEST_URI} !^/blah/index$
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /blah/([A-Za-z0-9_-]+)\ HTTP/
RewriteRule ^([A-Za-z0-9_-]+)$ /blah/cms/$1.php [L]
RewriteCond %{REQUEST_URI} ^/cms/inc/menu\.php$ [OR]
RewriteCond %{REQUEST_URI} ^/cms/inc/inmenu\.txt$
RewriteCond %{REQUEST_URI} ^/cms/inc/(menu\.php|inmenu\.txt$) Do you have two concurrent htaccess files along the same path... ?
RewriteCond %{REQUEST_URI} ^/blah/cms/$
RewriteRule ^cms/$ /blah/ [R=301,L]
RewriteBase /
RewriteCond %{REQUEST_URI} ^blah/cms/$
RewriteRule ^cms/$ /blah/ [R=301,L]
You have the rules in the right order: blocks [F], then redirects [R=301,L], then rewrites [L]. This is good.
It is often better to put all of the rules in the root htaccess taking great care with rule order.
If you are ever tempted to split code such that some is in the root htaccess and some is in a folder htaccess, beware that for every subfolder URL request, the root htaccess is evaluated first, then the folder htaccess. This can sometimes lead to weird operation and clashes. It is often better to put all of the rules in the root htaccess taking great care with rule order.
RewriteOptions inherit RewriteRule ^subdirectory/blahblah RewriteRule ^blahblah ... expect all RewriteRules in the root htaccess to be ignored for requests for the subdirectory.