【发布时间】:2013-07-11 18:03:43
【问题描述】:
我正在尝试设置友好的 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]
原则是我希望任何像http://www.example.co.uk/win,http://www.example.com/win这样的URL加载页面http://www.example.com/container.php?page=win或http://www.example.co.uk/games,http://www.example.com/games加载页面http://www.example.com/container.php?page=games。我还添加了排除图像、javascript、样式和包含目录的规则。
如果用户转到http://www.example.co.uk/index(.php or .htm or .html),那么它将重定向到http://www.example.com/home/。
由于某种原因,我的代码无法正常工作。我不明白为什么不。任何帮助将不胜感激。
【问题讨论】:
-
您同时使用 mod_alias 和 mod_rewrite。你想坚持一个
-
您能推荐一个替代方案吗?不知道有什么区别。我发现 Apache 文档非常混乱。
标签: php apache .htaccess mod-rewrite