【问题标题】:Friendly URL (Mod Rewrite) not working over Parked Domains友好的 URL(Mod 重写)不适用于停放的域
【发布时间】: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/winhttp://www.example.com/win这样的URL加载页面http://www.example.com/container.php?page=winhttp://www.example.co.uk/gameshttp://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


【解决方案1】:

您同时使用 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]

【讨论】:

  • 该页面应该是许多不同页面之一“获胜,游戏,笑话,视频,画廊......”有没有办法匹配除了图像,javascripts,包含和样式目录之外的所有内容?它还将地址栏中的 URL 更改为 example.com/container.php?page=win
猜你喜欢
  • 1970-01-01
  • 2017-08-24
  • 2015-01-04
  • 1970-01-01
  • 2012-05-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多