Forum Moderators: phranque
ErrorDocument 401 /error/unauthorized.php
ErrorDocument 404 /error/notfound.php
ErrorDocument 500 /error/server.phpDirectoryIndex home.php index.php index.html
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
RewriteEngine off
# Enable mod_rewrite, start rewrite engine
Options +FollowSymLinks
RewriteEngine on
#
# Internally rewrite search engine friendly static URL to dynamic filepath and query
RewriteRule ^photos/([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$ /photos.php?$1=$2&$3=$4 [L]
# Externally redirect client requests for old dynamic URLs to equivalent new static URLs
RewriteCond %{THE_REQUEST} ^[a-z0-9]{3,9}\ /photos\.php\?([^=]+)=([^&]+)&([^=]+)=([^\ ]+)\ HTTP/
RewriteRule ^photos\.php$ http://example.org/photos/%1/%2/%3/%4? [R=301,L]
[edited by: jdMorgan at 4:41 pm (utc) on Jan. 13, 2010]
[edit reason] example.org [/edit]
List the External Redirect first.
Add a standard non-www to www canonicalisation rule next.
List your Specific Rewrite next.
List your general (the one with .* in it) rewrite last and add the [L] flag to it.
Make sure that RewriteEngine On appears only once, and that it appears before all of this other code.
Remove the RewriteEngine Off line completely.
Options +FollowSymLinks
RewriteEngine on
# Externally redirect client requests for old dynamic URLs to equivalent new static URLs
RewriteCond %{THE_REQUEST} ^[a-z0-9]{3,9}\ /photos\.php\?([^=]+)=([^&]+)&([^=]+)=([^\ ]+)\ HTTP/
RewriteRule ^photos\.php$ http://www.example.org/photos/%1/%2/%3/%4? [R=301,L]RewriteCond %{HTTP_HOST} ^www\.(.*) [NC]
RewriteRule ^(.*) http://%1/$1 [R=301,L]
# Internally rewrite search engine friendly static URL to dynamic filepath and query
RewriteRule ^photos/([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$ /photos.php?$1=$2&$3=$4 [L]
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [L]
ErrorDocument 401 /error/unauthorized.php
ErrorDocument 404 /error/notfound.php
ErrorDocument 500 /error/server.php
DirectoryIndex home.php index.php index.html
[edited by: jdMorgan at 4:42 pm (utc) on Jan. 13, 2010]
[edit reason] Please use "example.com" or "example.org" only [/edit]
ErrorDocument 401 /error/unauthorized.php
ErrorDocument 404 /error/notfound.php
ErrorDocument 500 /error/server.php
#
DirectoryIndex home.php index.php index.html
#
Options +FollowSymLinks
RewriteEngine on
#
# Externally redirect client requests for old dynamic URL-paths (/photos.php?album=1234567890&image=
# 1234567890) to equivalent new static URLs (example.org/photos/album/1234567890/image/1234567890)
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /photos\.php\?album=([^&]+)&image=([^&#\ ]+)\ HTTP/
RewriteRule ^photos\.php$ http://www.example.org/photos/album/%1/image/%2? [R=301,L]
#
# Externally redirect client requests for old dynamic URL-paths (/photos.php?album=1234567890)
# to equivalent new static URLs ( example.org/photos/album/1234567890
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /photos\.php\?album=([^&#\ ]+)\ HTTP/
RewriteRule ^photos\.php$ http://www.example.org/photos/album/%1? [R=301,L]
#
# Externally redirect direct client requests for index page
# filepaths to "/" URLs, preserving directory & query string
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /([^/]+/)*((index¦home)\.php¦home\.html)([?#][^\ ]*)?\ HTTP/
RewriteRule ^(([^/]+/)*)((index¦home)\.php¦home\.html)$ http://www.example.org/photos/album/$1 [R=301,L]
#
# Externally redirect to remove "www"
RewriteCond %{HTTP_HOST} ^www\.([^.:/]+(\.[^.:/]+)+)\.?(:[0-9]+)?$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
#
# Internally rewrite search engine friendly static URL-path (/photos/album/1234567890/image/1234567890)
# to dynamic filepath and query (/photos.php?album=1234567890&image=1234567890)
RewriteRule ^photos/album/([^/]+)/image/([^/]+)$ photos.php?album=$1&image=$2 [L]
#
# Internally rewrite search engine friendly static URL-path (/photos/album/1234567890)
# to dynamic filepath and query (/photos.php?album=1234567890)
RewriteRule ^photos/album/([^/]+)$ photos.php?album=$1 [L]
#
# Rewrite remaining requests to .php script if requested URL-path does not already end with a filetype and
# does not resolve to an existing directory, but does resolve to existing file if ".php" is appended.
RewriteCond $1 !\.[a-z0-9]+$
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [L]
The exclusion of requests with appended filetypes in the last rule above is likely to have a good positive effect on the speed of your site. You may wish to make the pattern more-selective, but I suggest that you do not simply remove that RewriteCond.
Important: Replace all broken pipe "¦" characters above with solid pipe characters before use; Posting on this forum modifies the pipe characters.
Jim
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /index\.php\?catalog=([^&]+)&page=([^&#\ ]+)\ HTTP/
RewriteRule ^index\.php$ http://www.example.com/catalog-test/%1/%2/? [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /[i]catalog-test/[/i]index\.php\?catalog=([^&]+)&page=([^&#\ ]+)\ HTTP/
RewriteRule ^index\.php$ http://www.example.com/catalog-test/%1/%2/? [R=301,L]