如何为这些要求编写mod_rewrite规则?

时间:2010-12-22 16:53:41

标签: mod-rewrite

我需要为mod_rewrite制定规则:


http://site.kiev.ua/index.php
http://www.site.kiev.ua/
http://www.site.kiev.ua/index.php

http://site.kiev.ua/

http://site.kiev.ua/catalog/products/941

http://site.kiev.ua/catalog/products/941/

http://site.kiev.ua/catalog/products/941/index.php

http://site.kiev.ua/catalog/products/941/

941 - 它可以是任何类别

2 个答案:

答案 0 :(得分:1)

RewriteEngine On
RewriteBase /

# www to none www
RewriteCond %{HTTP_HOST} ^www.domain.com [NC]
RewriteRule ^(.*)$ http://domain.com/$1 [L,R=301]

# Remove index.php
RewriteCond %{THE_REQUEST} \ /(.+/)?index\.(html?|php)(\?.*)?\  [NC]
RewriteRule ^(.+/)?index\.(html?|php)$ ./$1 [R=301,L]

# Force trailing slashes.
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule [^/]$ %{REQUEST_URI}/ [R=301,L]

# /file.php to /file/
RewriteCond %{REQUEST_URI} ^(/.*[^/])/?$
RewriteCond %{DOCUMENT_ROOT}%1.php -f
RewriteRule ^([^/]+)/?$ ./$1.php [QSA,L]

答案 1 :(得分:0)

Options +FollowSymlinks -Indexes
RewriteEngine on

RewriteCond %{HTTP_HOST} ^www\.site\.kiev\.ua$ [NC]
RewriteRule ^(.*)$ http://site.kiev.ua/$1 [L,R=301]
相关问题