Forum Moderators: phranque
# Rewrite / to /cms/index.php
RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^$ /cms/index.php [L]
# Rewrite string to /cms/string.php
RewriteCond %{REQUEST_URI} !^/index$
RewriteRule ^([a-z0-9_\-]+)$ /cms/$1.php [NC,L]
# Rewrite cms/string.php to string (avoid duplicates)
RewriteCond %{THE_REQUEST} ^GET\ /cms/[^.]+\.php\ HTTP/
RewriteRule ^cms/([a-z0-9_\-]+)\.php$ /$1 [R=301,NC,L]
# Rewrite /laplume/ to /laplume/cms/index.php
RewriteCond %{REQUEST_URI} ^/laplume/$
RewriteRule ^$ /laplume/cms/index.php [L]
# Rewrite /laplume/string to /laplume/cms/string.php
RewriteCond %{REQUEST_URI} !^/laplume/index$
RewriteRule ^([a-z0-9_\-]+)$ /laplume/cms/$1.php [NC,L]
# Rewrite cms/string.php to string (avoid duplicates)
RewriteCond %{THE_REQUEST} ^GET\ /cms/[^.]+\.php\ HTTP/
RewriteRule ^cms/([a-z0-9_\-]+)\.php$ /$1 [R=301,NC,L]
# Rewrite laplume/cms/string.php to laplume/string (avoid duplicates)
RewriteCond %{THE_REQUEST} ^GET\ /laplume/cms/[^.]+\.php\ HTTP/
RewriteRule ^laplume/cms/([a-z0-9_\-]+)\.php$ /laplume/$1 [R=301,NC,L]
this second option does not work
# Forbid viewing specific files
RewriteCond %{REQUEST_URI} ^/cms/inc/(menu|list)\.php$ [OR]
RewriteCond %{REQUEST_URI} ^/laplume/cms/inc/(menu|list)\.php$
RewriteRule .* - [F]
# ROOT FOLDER
# For home page = /
# Request = GET / HTTP/1.1
RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^$ /cms/index.php [L]
# For other pages = /string
# Exclude /index
RewriteCond %{REQUEST_URI} !^/index$
# Request = GET /string HTTP/1.1
RewriteCond %{THE_REQUEST} ^GET\ /([A-Za-z0-9_\-]+)\ HTTP/
RewriteRule ^([A-Za-z0-9_\-]+)$ /cms/$1.php [L]
# /laplume/ FOLDER
# For home page = /laplume/
# Request = GET /laplume/ HTTP/1.1
RewriteCond %{REQUEST_URI} ^/laplume/$
RewriteRule ^$ /laplume/cms/index.php [L]
# For other pages = /laplume/string
# Exclude /laplume/index
RewriteCond %{REQUEST_URI} !^/laplume/index$
# Request = GET /laplume/string HTTP/1.1
RewriteCond %{THE_REQUEST} ^GET\ /laplume/([A-Za-z0-9_\-]+)\ HTTP/
RewriteRule ^([A-Za-z0-9_\-]+)$ /laplume/cms/$1.php [L]
ErrorDocument 404 /error404.php
# Forbid viewing specific files
RewriteCond %{REQUEST_URI} ^/cms/inc/(menu|list)\.php$ [OR]
RewriteCond %{REQUEST_URI} ^/laplume/cms/inc/(menu|list)\.php$
RewriteRule .* - [F]
RewriteCond %{REQUEST_URI} ^(/laplume)?/cms/inc/(menu|list)\.php$ RewriteRule ^(/laplume)?/cms/inc/(menu|list)\.php$ - [F] RewriteRule ^(laplume/)?(blahblah) /$1cms/$2.php [L] # Exclude /index
RewriteCond %{REQUEST_URI} !^/index$
# Request = GET /string HTTP/1.1
RewriteCond %{THE_REQUEST} ^GET\ /([A-Za-z0-9_\-]+)\ HTTP/
RewriteRule ^([A-Za-z0-9_\-]+)$ /cms/$1.php [L] RewriteCond %{REQUEST_URI} ^/laplume/$
RewriteRule ^$ /laplume/cms/index.php [L]
AddDefaultCharset UTF-8
Options +FollowSymLinks
RewriteEngine on
ErrorDocument 404 /error404.php
RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^$ /cms/index.php [L]
RewriteCond %{REQUEST_URI} !^/index$
RewriteCond %{THE_REQUEST} ^GET\ /([A-Za-z0-9_\-]+)\ HTTP/
RewriteRule ^([A-Za-z0-9_\-]+)$ /cms/$1.php [L]
RewriteCond %{REQUEST_URI} ^/laplume/$
RewriteRule ^$ /laplume/cms/index.php [L]
RewriteCond %{REQUEST_URI} !^/laplume/index$
RewriteCond %{THE_REQUEST} ^GET\ /laplume/([A-Za-z0-9_\-]+)\ HTTP/
RewriteRule ^([A-Za-z0-9_\-]+)$ /laplume/cms/$1.php [L]
example.com/ and example.com/laplume/ - that is what you should be linking to in the navigation links of your site as href="/" and href="/laplume/". ^$ and ^laplume/ and internally rewrite as appropriate. Options +FollowSymLinks
RewriteEngine on
ErrorDocument 404 /error404.php
# 1. Rules that block malicious requests go here.
# 11. Block access
RewriteRule ^/(laplume/)?/cms/inc/(menu|list)\.php$ - [F]
# 2. External Redirects
# 21a. Redirect for index or index.php URL request in /laplume/cms/ folder
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /laplume/cms/([^/]+/)*index(\.php)?\ HTTP/
RewriteRule ^laplume/cms/(([^/]+/)*)index(\.php)?$ http://www.example.com/laplume/$1? [R=301,L]
# 21b. Redirect for folder URL request in /laplume/cms/ folder
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /laplume/cms/([^/]+/)*\ HTTP/
RewriteRule ^laplume/cms/(([^/]+/)*)$ http://www.example.com/laplume/$1? [R=301,L]
# 21c. Redirect for page or .php file URL request in /laplume/cms/ folder
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /laplume/cms/([^/]+/)*[^/.]+(\.php)?\ HTTP/
RewriteRule ^laplume/cms/(([^/]+/)*[^/.]+)(\.php)?$ http://www.example.com/laplume/$1? [R=301,L]
# 22a. Redirect for index or index.php URL request in /laplume/ folder
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /laplume/([^/]+/)*index(\.php)?\ HTTP/
RewriteRule ^laplume/(([^/]+/)*)index(\.php)?$ http://www.example.com/laplume/$1? [R=301,L]
# 22b. Redirect for .php file URL request in /laplume/ folder
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /laplume/([^/]+/)*[^/.]+\.php\ HTTP/
RewriteRule ^laplume/(([^/]+/)*[^/.]+)\.php$ http://www.example.com/laplume/$1? [R=301,L]
# 23a. Redirect for index or index.php URL request in /cms/ folder
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /cms/([^/]+/)*index(\.php)?\ HTTP/
RewriteRule ^cms/(([^/]+/)*)index(\.php)?$ http://www.example.com/$1? [R=301,L]
# 23b. Redirect for folder URL request in /cms/ folder
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /cms/([^/]+/)*\ HTTP/
RewriteRule ^cms/(([^/]+/)*)$ http://www.example.com/$1? [R=301,L]
# 23c. Redirect for page or .php file URL request in /cms/ folder
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /cms/([^/]+/)*[^/.]+(\.php)?\ HTTP/
RewriteRule ^cms/(([^/]+/)*[^/.]+)(\.php)?$ http://www.example.com/$1? [R=301,L]
# 24a. Redirect for index or index.php URL request in root folder
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index(\.php)?\ HTTP/
RewriteRule ^(([^/]+/)*)index(\.php)?$ http://www.example.com/$1? [R=301,L]
# 24b. Redirect for .php file URL request in root folder
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*[^/.]+\.php\ HTTP/
RewriteRule ^(([^/]+/)*[^/.]+)\.php$ http://www.example.com/$1? [R=301,L]
# 25. non-www/www canonicalisation redirect
RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
# 3. Internal Rewrites
# 31. Rewrite example.com/laplume/ URL request
RewriteRule ^laplume/$ /laplume/cms/index.php [L]
# 32a. Rewrite example.com/laplume/pages URL requests
RewriteRule ^laplume/([a-z0-9-]+)$ /laplume/cms/$1.php [L]
# 32b. Rewrite example.com/laplume/FOLDER/pages URL requests
# RewriteRule ^laplume/(([^/]+/)*[a-z0-9-]+)$ /laplume/cms/$1.php [L]
# 33. Rewrite example.com/laplume/FOLDER/ file requests
RewriteRule ^laplume/(([^/]+/)*[a-z0-9-]+\.(css|jpg|js|png))$ /laplume/cms/$1 [L]
# 34. Rewrite example.com/ URL request (root)
RewriteRule ^$ /cms/index.php [L]
# 35a. Rewrite example.com/pages URL requests
RewriteRule ^([a-z0-9-]+)$ /cms/$1.php [L]
# 35b. Rewrite example.com/FOLDER/pages URL requests
# RewriteRule ^(([^/]+/)*[a-z0-9-]+)$ /cms/$1.php [L]
# 36. Rewrite example.com/FOLDER/ file requests
RewriteRule ^(([^/]+/)*[a-z0-9-]+\.(css|jpg|js|png))$ /cms/$1 [L]
RewriteRule ^laplume/$ /laplume/cms/index.php [L]
RewriteRule ^laplume/$ /laplume/cms/index.php [L] example.com/laplume/ AND there's a file inside the server at /laplume/cms/index.php and the script is able to detect that /laplume/ was requested and it has some content to deliver for that request, then it should work.
What is the reason why redirects need full URLs?
RewriteRule ^laplume/$ /laplume/cms/index.php [L] g1smd: If you requested example.com/laplume/ AND there's a file inside the server at /laplume/cms/index.php and the script is able to detect that /laplume/ was requested and it has some content to deliver for that request, then it should work.
# Redirect GET /cms/string.php HTTP/1.1 to /string (the link)
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] # Redirect GET /laplume/cms/string.php HTTP/1.1 to /laplume/string (the link)
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /laplume/cms/([A-Za-z0-9_-]+)\.php\ HTTP/
RewriteRule ^laplume/cms/([A-Za-z0-9_-]+)\.php$ /laplume/$1 [R=301,L]
RewriteCond %{REQUEST_URI} ^/laplume/$
RewriteRule ^$ /laplume/cms/index.php [L]
RewriteCond %{REQUEST_URI} !^/laplume/index$
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /laplume/([A-Za-z0-9_-]+)\ HTTP/
RewriteRule ^([A-Za-z0-9_-]+)$ /laplume/cms/$1.php [L] AddDefaultCharset UTF-8
Options +FollowSymLinks
RewriteEngine on
ErrorDocument 404 /error404.php
RewriteCond %{REQUEST_URI} ^/laplume/cms/inc/menu\.php$ [OR]
RewriteCond %{REQUEST_URI} ^/laplume/cms/admin/list\.php$ [OR]
RewriteCond %{REQUEST_URI} ^/laplume/cms/([A-Za-z0-9_-]+)\.txt$ [OR]
RewriteCond %{REQUEST_URI} ^/laplume/cms/comments/([A-Za-z0-9_-]+)\.txt$ [OR]
RewriteCond %{REQUEST_URI} ^/laplume/img/$ [OR]
RewriteCond %{REQUEST_URI} ^/cms/inc/menu\.php$ [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} ^/laplume/$
RewriteRule ^$ /laplume/cms/index.php [L]
RewriteCond %{REQUEST_URI} !^/laplume/index$
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /laplume/([A-Za-z0-9_-]+)\ HTTP/
RewriteRule ^([A-Za-z0-9_-]+)$ /laplume/cms/$1.php [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] # Redirect GET /cms/string.php HTTP/1.1 to /string (the link)
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] I think maybe you need to step back again. Forget RewriteRules and simply list all the forms of URL that a human could possibly ask for. For each form, what do you want their address bar to say?
# GET /laplume/ HTTP/1.1
RewriteRule ^laplume/$ /laplume/cms/index.php [L]
# GET /laplume/ HTTP/1.1
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /laplume/\ HTTP/
RewriteRule ^$ /laplume/cms/index.php [L]