Forum Moderators: phranque
[1]http://example.com/foo.php [2]http://example.com/foo
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
http://foo.com/foo or http:// foo. com/foo? foo=foo
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /([^/]+/)*[^.#?\ ]+\.php([#?][^\ ]*)?\ HTTP/
RewriteRule ^(([^/]+/)*[^.]+)\.php http://example.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^example.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.example.com$
RewriteRule ^blog\/?(.*)$ "http\:\/\/blog\.example\.com\/$1" [R=301,L]
[edited by: jdMorgan at 7:56 pm (utc) on Jun 7, 2010]
[edit reason] example.com [/edit]
- redirect index.php URL requests to example.com/
- redirect .php URL requests to correct extensionless URL (this redirect will never affect index.php because the rule above has already fixed that problem)
- redirect non-www to www (canonical 301 redirect)
- rewrite extensionless URL requests to the correct .php file. DirectoryIndex index.php directive to ensure that URL requests for "/" are served by the index.php file, and you're done.
#this should remove index.php but it dosent.. it takes you one level up though
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /([^/]+/)*[^.#?\ ]+\.php([#?][^\ ]*)?\ HTTP/
RewriteRule ^(([^/]+/)*[^.]+)\.php http://example.com/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
the url changes from
http://example.com/index.php?page
to
http://example.com/index?page
but it should have been
http://example.com/?page
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /([^/]+/)*index\.php([#?][^\ ]*)?\ HTTP/
RewriteRule ^(([^/]+/)*index\.php http://example.com/ [R=301,L]
#RewriteCond %{THE_REQUEST} ^[A-Z]+\ /([^/]+/)*index\.php([#?][^\ ]*)?\ HTTP/
#RewriteRule ^([^/]+/)*index\.php http://example.com/$1 [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /([^/]+/)*index\.php([#?][^\ ]*)?\ HTTP/
RewriteRule ^(([^/]+[b]/)*)i[/b]ndex\.ph[b]p$[/b] http://example.com/$1 [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /([^/]+/)*index\.php([#?][^\ ]*)?\ HTTP/
RewriteRule ^(([^/]+/)*)index\.php$ http://example.com/$1 [R=301,L]
RewriteEngine on
AddType application/x-httpd-php .xml
RewriteCond %{HTTP_HOST} ^example.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.example.com$
RewriteRule ^blog\/?(.*)$ "http\:\/\/blog\.example\.com\/$1" [R=301,L]
RewriteCond %{HTTP_HOST} ^example.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.example.com$
RewriteRule ^movies\/?(.*)$ "http\:\/\/movies\.example\.com\/$1" [R=301,L]
RewriteCond %{HTTP_HOST} ^example.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.example.com$
RewriteRule ^sms\/?(.*)$ "http\:\/\/sms\.example\.com\/$1" [R=301,L]
RewriteCond %{HTTP_HOST} ^example.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.example.com$
RewriteRule ^articles\/?(.*)$ "http\:\/\/articles\.example\.com\/$1" [R=301,L]
RewriteCond %{HTTP_HOST} ^example.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.example.com$
RewriteRule ^admin\/?(.*)$ "http\:\/\/admin\.example\.com\/$1" [R=301,L]
RewriteCond %{HTTP_HOST} ^www.example.com$
RewriteRule ^(.*)$ "http\:\/\/example\.com\/$1" [R=301,L]
RewriteCond %{HTTP_HOST} ^example.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.example.com$
RewriteRule ^resources\/?(.*)$ "http\:\/\/resources\.example\.com\/$1" [R=301,L]
RewriteCond %{HTTP_HOST} ^example.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.example.com$
RewriteRule ^images\/?(.*)$ "http\:\/\/images\.example\.com\/$1" [R=301,L]
RewriteCond %{HTTP_HOST} ^example.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.example.com$
RewriteRule ^js\/?(.*)$ "http\:\/\/js\.example\.com\/$1" [R=301,L]
RewriteCond %{HTTP_HOST} ^example.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.example.com$
RewriteRule ^css\/?(.*)$ "http\:\/\/css\.example\.com\/$1" [R=301,L]
RewriteCond %{HTTP_HOST} ^example.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.example.com$
RewriteRule ^feeds\/?(.*)$ "http\:\/\/feeds\.example\.com\/$1" [R=301,L]
#this index.php removal works now
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /([^/]+/)*index\.php([#?][^\ ]*)?\ HTTP/
RewriteRule ^(([^/]+/)*)index\.php$ http://example.com/$1 [R=301,L]
#the code below this causes a redirect loop on any page which is not index.php or directory
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /([^/]+/)*[^.#?\ ]+\.php([#?][^\ ]*)?\ HTTP/
RewriteRule ^(([^/]+/)*[^.]+)\.php http://example.com/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
[edited by: jdMorgan at 2:24 pm (utc) on Jun 18, 2010]
[edit reason] Example.com [/edit]
RewriteCond %{HTTP_HOST} ^example.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.example.com$ RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ "http\:\/\/blog\.example\.com\/$1" http://blog.example.com/$1 [edited by: jdMorgan at 2:25 pm (utc) on Jun 18, 2010]
[edit reason] example.com [/edit]
#this one removes the index.php
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /([^/]+/)*index\.php([#?][^\ ]*)?\ HTTP/
RewriteRule ^(([^/]+/)*)index\.php$ http://example.com/$1 [R=301,L]
#this here removes the .php
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /([^/]+/)*[^.#?\ ]+\.php([#?][^\ ]*)?\ HTTP/
RewriteRule ^(([^/]+/)*[^.]+)\.php http://example.com/$1 [R=301,L]
#and this one does an internal rewrite to fetch the desired file
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
RewriteRule %{REQUEST_URI} !\.(gif|jpe?g|png|css|js|zip)$
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /([^/]+/)*index\.php([#?][^\ ]*)?\ HTTP/
RewriteRule ^(([^/]+/)*)index\.php$ http://example.com/$1 [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /([^/]+/)*[^.#?\ ]+\.php([#?][^\ ]*)?\ HTTP/
RewriteRule ^(([^/]+/)*[^.]+)\.php http://example.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^www.example.com$
RewriteRule ^(.*)$ "http\:\/\/example\.com\/$1" [R=301,L]
RewriteRule %{REQUEST_URI} !\.(gif|jpe?g|png|css|js|zip)$
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
[edited by: jdMorgan at 2:27 pm (utc) on Jun 18, 2010]
[edit reason] example.com [/edit]
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /([^/]+/)*index\.php([#?][^\ ]*)?\ HTTP/
RewriteRule ^(([^/]+/)*)index\.php$ http://example.com/$1 [R=301,L]
#
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /([^/]+/)*[^.#?\ ]+\.php([#?][^\ ]*)?\ HTTP/
RewriteRule ^(([^/]+/)*[^.]+)\.php http://example.com/$1 [R=301,L]
#
RewriteCond %{HTTP_HOST} ^www\.example\.c[b]om[/b]
RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]
#
RewriteRule %{REQUEST_URI} !\.(gif|jpe?g|png|css|js|zip)$
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ [b]/$1[/b].php [b][L][/b]
RewriteRule ^(.*)$ /$1.php [L] RewriteRule ^(.*)$ $1.php [L]
http://www.admin.example.com/stats does not change to http://admin.example.com/stats
BUT
http://www.admin.example.com/stats.php or http://www.admin.example.com/index.php
DO change to http://admin.example.com/stats and http://admin.example.com/ respectively..
[edited by: jdMorgan at 1:35 pm (utc) on Jun 19, 2010]
[edit reason] De-linked [/edit]