0

我正在尝试设置友好的 URL 来处理停放的域。我有以下 .htaccess 文件:

RewriteEngine On

RedirectMatch ^/$ http://www.example.com/home/
RedirectMatch ^/[index.php|index.html|index.html]$ http://www.example.com/home/

RewriteCond  %{REQUEST_URI} ^/home[/]*$
RewriteRule ^/home[/]*$ http://www.example.com/container.php?page=index [P]

RewriteCond  %{REQUEST_URI} [a-z]*[|/](images|styles|javascripts|includes)(.*)
RewriteRule [a-z]*[|/](images|styles|javascripts|includes)(.*) http://www.example.com/$1/$2 [P]

RewriteCond  %{REQUEST_URI} !(images/|styles/|javascripts/|includes/) 
RewriteRule ([a-z]*)[/]$ http://www.example.com/container.php?page=$1 [P]
RewriteCond %{HTTP_HOST} ^example\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.example\.com$
RewriteRule ^/?$ "http\:\/\/www\.example\.com\/home\/" [R=301,L]

原则是,我想要任何 URL http://www.example.co.uk/winhttp://www.example.com/win加载页面http://www.example.com/container.php?page=win或加载页面。我还添加了排除图像、javascript、样式和包含目录的规则。http://www.example.co.uk/gameshttp://www.example.com/gameshttp://www.example.com/container.php?page=games

如果用户去,http://www.example.co.uk/index(.php or .htm or .html)那么它将重定向到http://www.example.com/home/.

出于某种原因,我的代码无法正常工作。我不明白为什么不。任何帮助将不胜感激。

4

1 回答 1

0

您同时使用 mod_alias 和 mod_rewrite,我认为您不需要排除静态内容,因为您只路由 4 个静态条目。清理 .htaccess 文件并尝试一下。

RewriteEngine On

RewriteRule ^/$ http://www.example.com/home/
RewriteRule ^index.(html|php|htm)$ http://www.example.com/home/ 
RewriteCond  %{REQUEST_URI} !(images\/|styles\/|javascripts/|includes/) 
RewriteRule  ^([a-zA-Z]*)/$ http://www.example.com/container.php?page=$1 [P]
于 2013-07-11T09:54:03.567 回答