Forum Moderators: phranque
#Redirect .com/main/page.php to the variable of $category_type and $category_name
RewriteRule ^(main)/([^.,^/]+)\.php$ /index.php?category_type=main&category_name=$2 [L]
Options +FollowSymLinks
RewriteEngine On
#Redirect any / to index.html
RewriteCond %{REQUEST_URI} /[A-Za-z0-9-\./]+/$
RewriteRule (.*) /$1index.html [R=301,L]
#Redirect .com/main/page.php to the variable of $category_type and $category_name
RewriteRule ^(main)/([^.,^/]+)\.php$ /index.php?category_type=main&category_name=$2 [L]
#Redirect .com/main/payment-verify.php&id=has221 to the variable of $category_id and $category_name and others
RewriteRule ^(main)/([^.,^/]+)\.php(&.*)$ /index.php?category_type=main&category_name=$2&$3 [L]
#Redirect .com/123-categoryname/index.html to the variable of $category_id and $category_name
RewriteRule ^([0-9]*)\-([^.,^/]+)/index\.html$ /index.php?category_id=$1&category_name=$2 [L]
#Redirect .com/123-categoryname/12-pagename to the variable of $category_id, $category_name and others
RewriteRule ^([0-9]*)\-([^.,^/]+)/([0-9]*)\-([^/]+)$ /index.php?category_id=$1&category_name=$2&product_id=$3&product_name=$4 [L]
#For redirect user to www.example.com if they ask for example.com
RewriteCond %{http_host} ^example.com [nc]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,nc]
(main)/([^.,^/]+)\.php(&.*) example.com/main/payment-verify.php&id=has221 on your site? [edited by: g1smd at 11:19 am (utc) on Apr 28, 2011]
Options +FollowSymLinks
RewriteEngine On
#Redirect any / to index.html
RewriteCond %{REQUEST_URI} /[A-Za-z0-9-\./]+/$
RewriteRule (.*) /$1index.html [R=301,L]
#For redirect user to www.example.com if they ask for example.com
RewriteCond %{http_host} ^example.com [nc]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,nc,L]
#Redirect .com/main/page.php to the variable of $category_id and $category_name
RewriteRule ^(main)/([^/.]+)\.php$ /index.php?category_type=main&category_name=$2 [L]
#Redirect .com/main/payment-verify.php?id=has221 to the variable of $category_id and $category_name and others
RewriteRule ^(main)/([^/.]+)\.php(&.*)$ /index.php?category_type=main&category_name=$2&$3 [L]
#Redirect .com/123-categoryname/ to the variable of $category_id and $category_name
RewriteRule ^([0-9]*)\-([^/.]+)/index\.html$ /index.php?category_id=$1&category_name=$2 [L]
#Redirect .com/123-categoryname/12-pagename to the variable of $category_id, $category_name and others
RewriteRule ^([0-9]*)\-([^/.]+)/([0-9]*)\-([^/]+)$ /index.php?category_id=$1&category_name=$2&product_id=$3&product_name=$4 [L]
RewriteRule ^([0-9]*)\-([^/.]+)/([0-9]*)\-([^/]+)$ example.com/-words/-words DirectoryIndex index.html index.php
Options +FollowSymLinks
RewriteEngine On
# Externally redirect only direct client requests for /index.php
# and /index.html and /index.htm to URL ending with slash.
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.(html?|php)\ HTTP/
RewriteRule ^(([^/]+/)*)index\.(html?|php)$ http://www.example.com/$1 [R=301,L]
# Externally redirect to canonicalize the domain name if a non-canonical
# hostname is requested, in order to prevent duplicate-content problems
RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
#REWRITE .com/main/page.php to the variable of $category_type and $category_name
RewriteCond %{QUERY_STRING} !.
RewriteRule ^(main)/([^/.]+)\.php$ /index.php?category_type=$1&category_name=$2 [L]
#REWRITE .com/main/payment-verify.php?id=has221 to the variable of $category_id and $category_name and others
RewriteCond %{QUERY_STRING} (^|&)id=([^&]+)(&|$)
RewriteRule ^(main)/([^/.]+)\.php$ /index.php?category_type=$1&category_name=$2&id=%2 [L]
#REWRITE .com/123-categoryname/ to the variable of $category_id and $category_name
RewriteRule ^([0-9]+)-([^/.]+)/$ /index.php?category_id=$1&category_name=$2 [L]
#REWRITE .com/123-categoryname/12-pagename to the variable of $category_id, $category_name and others
RewriteRule ^([0-9]+)-([^/.]+)/([0-9]+)-([^/.]+)$ /index.php?category_id=$1&category_name=$2&product_id=$3&product_name=$4 [L] [edited by: g1smd at 11:30 am (utc) on Apr 28, 2011]
www.example.com/ to show the index page content without needing "index" in the URL. www.example.com/<anything>/index.php to example.com/<anything>/ ending in a trailing slash. Does same for index.html and index.htm too. #REWRITE .com/main/payment-verify.php?id=has221 to the variable of $category_id and $category_name and others
RewriteCond %{QUERY_STRING} .
RewriteRule ^(main)/([^/.]+)\.php$ /index.php?category_type=$1&category_name=$2 [QSA,L] www.example.com/folder/index.html Server: www.example.com
GET /folder/index.html HTTP/1.1 ^[A-Z]{3,9}\ matches the GET, POST, HEAD, etc, part of the request. DirectoryIndex index.html index.php
Options +FollowSymLinks
RewriteEngine On
#Redirect .com/index.html .php .htm to .com/
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.(html?|php)\ HTTP/
RewriteRule ^(.*)$ http://www.example.com/ [R=301,L]
#Redirect .com/12-category-name/ to .com/12-category-name/index.html
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([0-9]+)-([^/.]+)/\ HTTP/
RewriteRule ^(.*)/$ http://www.example.com/%1-%2/index.html [R=301,L]
#Rewrite .com/12-category-name/index.html to index.php?category_id=12&category_name=category-name
RewriteRule ^([0-9]+)-([^/.]+)/index\.html$ /index.php?category_id=$1&category_name=$2 [L]
#Rewrite .com/12-category-name/index-2.html to index.php?category_id=12&category_name=category-name&page_number=2
RewriteRule ^([0-9]+)-([^/.]+)/index-([0-9]+)\.html$ /index.php?category_id=$1&category_name=$2&page_number=$3 [L]
#Rewrite .com/12-category-name/54-page-name.html to index.php?category_id=12&category_name=category-name and further
RewriteRule ^([0-9]+)-([^/.]+)/([0-9]+)-([^/.]+)\.html$
/index.php?category_id=$1&category_name=$2&page_id=$3&page_name=$4 [L]
#Rewrite .com/main/page-name.html to index.php?category_name=main&page_name=page-name
RewriteCond %{QUERY_STRING} !.
RewriteRule ^(main)/([^/.]+)\.html$ /index.php?category_name=$1&page_name=$2 [L]
#Rewrite .com/main/page-name.html?any=any to index.php?category_name=main&page_name=page-name&any=any
RewriteCond %{QUERY_STRING} .
RewriteRule ^(main)/([^/.]+)\.html$ /index.php?category_name=$1&page_name=$2 [QSA,L]
#Redirect any .com/css/ to .com/css/index.html
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)+\ HTTP/
RewriteRule ^([^/]+/)+$ http://www.example.com/$1index.html [R=301,L]
# Externally redirect to canonicalize the domain name if a non-canonical
# hostname is requested, in order to prevent duplicate-content problems
RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
DirectoryIndex index.html index.php
Options +FollowSymLinks
RewriteEngine On
#Redirect .com/index.html .php .htm to .com/
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.(html?|php)\ HTTP/
RewriteRule ^index\.(html?|php)$ http://www.example.com/ [R=301,L]
#Redirect .com/12-category-name/ to .com/12-category-name/index.html
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([0-9]+)-([^/.]+)/\ HTTP/
RewriteRule ^([0-9]+)-([^/.]+)/$ http://www.example.com/$1-$2/index.html [R=301,L]
#Redirect any .com/css/ to .com/css/index.html
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)+\ HTTP/
RewriteRule ^([^/]+/)+$ http://www.example.com/$1index.html [R=301,L]
# Externally redirect to canonicalize the domain name if a non-canonical
# hostname is requested, in order to prevent duplicate-content problems
RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
#Rewrite .com/main/page-name.html to index.php?category_name=main&page_name=page-name
RewriteCond %{QUERY_STRING} !.
RewriteRule ^(main)/([^/.]+)\.html$ /index.php?category_name=$1&page_name=$2 [L]
#Rewrite .com/main/page-name.html?any=any to index.php?category_name=main&page_name=page-name&any=any
RewriteCond %{QUERY_STRING} .
RewriteRule ^(main)/([^/.]+)\.html$ /index.php?category_name=$1&page_name=$2 [QSA,L]
#Rewrite .com/12-category-name/index.html to index.php?category_id=12&category_name=category-name
RewriteRule ^([0-9]+)-([^/.]+)/index\.html$ /index.php?category_id=$1&category_name=$2 [L]
#Rewrite .com/12-category-name/index-2.html to index.php?category_id=12&category_name=category-name&page_number=2
RewriteRule ^([0-9]+)-([^/.]+)/index-([0-9]+)\.html$ /index.php?category_id=$1&category_name=$2&page_number=$3 [L]
#Rewrite .com/12-category-name/54-page-name.html to index.php?category_id=12&category_name=category-name and further
RewriteRule ^([0-9]+)-([^/.]+)/([0-9]+)-([^/.]+)\.html$ /index.php?category_id=$1&category_name=$2&page_id=$3&page_name=$4 [L]
Redirecting TO index.html will likely come back to haunt you as a big problem at some time in the future.
www.example.com/folder/ and not www.example.com/folder/index.html. www.example.com/folder/ and redirecting all index document URLs to that canonical URL ending with a slash, alleviates that problem and all future problems.