【问题标题】:Apache not redirecting properly '/usr/home/username/public_html/'Apache 没有正确重定向 '/usr/home/username/public_html/'
【发布时间】:2014-12-05 04:02:04
【问题描述】:

我正在使用它来将非 www 请求重定向到 www

  RewriteCond %{HTTP_HOST} !^www\.
  RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

它应该重定向自:

http://example.com/intranet

收件人:

http://www.example.com/intranet

但它正在重定向到:

http://www.example.com//usr/home/username/public_html/intranet

发生了什么,我该如何解决?

【问题讨论】:

  • 你是把它放到虚拟主机配置中还是直接放到.htaccess
  • 我已经把它放到了一个 .htaccess 文件的子目录中,'intranet'。
  • 这很好奇。我有类似的事情可以做相反的工作并且效果很好:RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC] RewriteRule ^(.*)$ http://%1/$1 [R=301,L,QSA]
  • 如果您的 .htaccess 在 /intranet/ 内,则添加 RewriteBase /intranet/
  • @Cheery:为什么?它将改变传递给SAPI的请求字符串(我以/intranet为例,一个真实的站点可能有几十个不同的路径)

标签: php apache .htaccess mod-rewrite


【解决方案1】:

我已经成功使用了以下内容:

RewriteBase /intranet/
RewriteCond %{HTTP_HOST}   !^www\. [NC]
RewriteRule ^(.*)          http://www.%{HTTP_HOST}/$1 [L,R]

【讨论】:

  • 你是在根目录还是在子目录中使用?
  • 我在子目录中使用它。
  • 只是想提一下)
  • 在本地测试上述内容并使用http://htaccess.madewithlove.be/
猜你喜欢
  • 1970-01-01
  • 2020-02-05
  • 2010-10-22
  • 2016-04-14
  • 2020-02-10
  • 2018-04-14
  • 2021-12-06
  • 2020-05-13
  • 1970-01-01
相关资源
最近更新 更多