Forum Moderators: phranque
Options +Indexes
Options +FollowSymlinks
RewriteEngine on
RewriteBase /
# redirect all non-canonical hostname requests to canonical hostname
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\.example\.com$
RewriteRule (.*) http://www.example.com/$1 [R=301,L] Options +Indexes
Options +FollowSymlinks
RewriteEngine on
RewriteBase /en/
# redirect all non-canonical hostname requests to canonical hostname
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\.example\.com$
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
# rewrite .php extension to virtual folder
# RewriteRule ^pattern-for-the-path-part-of-URL-request /place-inside-server-where-content-resides [R=301,L]
# redirect index.php to folder
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*index\.php\ HTTP/
RewriteRule ^(.*)index\.php$ http://%{HTTP_HOST}/$1 [R=301,L]
# force trailing slash
RewriteCond %{REQUEST_URI} !(.*)/$ [edited by: g1smd at 12:30 pm (utc) on Feb 22, 2010]
So, what I need is a set of rewrite conditions/ rules to rewrite my .php file extensions to a virtual folder ...
RewriteRule ^english/news/$ /english/news.php [L] RewriteRule ^([^/]+)/([^/]+)/$ /$1/$2.php [L] # NEVER LIST REWRITES BEFORE REDIRECTS, IDIOT!
Options +Indexes
Options +FollowSymlinks
RewriteEngine on
RewriteBase /en/
# rewrite .php extension to virtual folder
# RewriteRule ^pattern-for-the-path-part-of-URL-request /place-inside-server-where-content-resides [R=301,L]
# redirect index.php to folder
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*index\.php\ HTTP/
RewriteRule ^(.*)index\.php$ http://%{HTTP_HOST}/$1 [R=301,L]
# force trailing slash
RewriteCond %{REQUEST_URI} !(.*)/$
# redirect all non-canonical hostname requests to canonical hostname
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\.example\.com$
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
# NEVER LIST REWRITES BEFORE REDIRECTS, IDIOT!
Options +Indexes
Options +FollowSymlinks
RewriteEngine on
RewriteBase /
# url to filepath
RewriteRule ^([^/]+)/([^/]+)/$ /$1/$2.php [L]
# redirect index.php to folder
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*index\.php\ HTTP/
RewriteRule ^(.*)index\.php$ http://%{HTTP_HOST}/$1 [L]
# redirect all non-canonical hostname requests to canonical hostname
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\.example\.com$
RewriteRule (.*) http://www.example.com/$1 [R=301,L] DirectoryIndex index.php statement ahead of all of this stuff.
Options +Indexes
Options +FollowSymlinks
RewriteEngine on
RewriteBase /
DirectoryIndex index.php
# REDIRECT index.php to folder
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*index\.php\ HTTP/
RewriteRule ^(.*)index\.php$ http://%{HTTP_HOST}/$1 [L]
# REDIRECT all non-canonical hostname requests to canonical hostname
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\.example\.com$
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
# REWRITE url to filepath
RewriteRule ^([^/]+)/([^/]+)/$ /$1/$2.php [L] RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]*/)*index\.(html?|php[45]?)(\?[^\ ]*)?\ HTTP/
RewriteRule ^(([^/]*/)*)index\.(html?|php[45]?)$ http://www.example.com/$1 [R=301,L] Options +Indexes
Options +FollowSymlinks
RewriteEngine on
RewriteBase /
DirectoryIndex index.php
# REDIRECT Force requests for named index files to drop the index file filename, and force www:
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]*/)*index\.(html?|php[45]?)(\?[^\ ]*)?\ HTTP/
RewriteRule ^(([^/]*/)*)index\.(html?|php[45]?)$ http://www.example.com/$1 [R=301,L]
# REDIRECT all non-canonical hostname requests to canonical hostname
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\.example\.com$
RewriteRule (.*) http://www.example.com/$1 [R=301,L] Options +Indexes
Options +FollowSymlinks
RewriteEngine on
RewriteBase /
DirectoryIndex index.php
# REDIRECT Force requests for named index files to drop the index file filename, and force www to avoid redirect chains:
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]*/)*index\.(html?|php[45]?)(\?[^\ ]*)?\ HTTP/
RewriteRule ^(([^/]*/)*)index\.(html?|php[45]?)$ http://www.example.com/$1 [R=301,L]
# REDIRECT all non-canonical hostname requests to canonical hostname
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\.example\.com$
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
# REWRITE url to filepath
RewriteRule ^([^/]+)/([^/]+)/$ /$1/$2.php [L] [edited by: jabz at 10:30 pm (utc) on Feb 22, 2010]
^([^/]+)/([^\.]+)\.php pattern to match these URL requests, and then use $1 and $2 as the substitution/target. As it is a redirect it will also need the domain name and the R=301 and L flags as before. RewriteCond looking at %{THE_REQUEST} to detect the fact the request came from the client, not as the result of any internal rewriting action. RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+)/([^\.]+)\.php\ HTTP/
RewriteRule ^(english¦french)/([^.]+)\.php$ http://www.example.com/$1/$2 [R=301,L] [edited by: g1smd at 11:37 pm (utc) on Feb 22, 2010]
RewriteRule ^([^/]+)/([^/]+)/$ /$1/$2.php [L] RewriteRule ^([^/]+)/([^/.]+)$ /$1/$2.php [L] Options +Indexes
Options +FollowSymlinks
RewriteEngine on
RewriteBase /
DirectoryIndex index.php
# REDIRECT Force requests for named index files to drop the index file filename, and force www to avoid redirect chains:
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]*/)*index\.(html?|php[45]?)(\?[^\ ]*)?\ HTTP/
RewriteRule ^(([^/]*/)*)index\.(html?|php[45]?)$ http://www.example.com/$1 [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+)/([^\.]+)\.php\ HTTP/
RewriteRule ^(en|de|ar)/([^.]+)\.php$ http://www.example.com/$1/$2 [R=301,L]
# REDIRECT all non-canonical hostname requests to canonical hostname
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\.example\.com$
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
# REWRITE url to filepath
RewriteRule ^([^/]+)/([^/.]+)$ /$1/$2.php [L] [edited by: jabz at 12:18 am (utc) on Feb 23, 2010]