【问题标题】:rewrite htaccess causes infinite loop?重写 htaccess 导致无限循环?
【发布时间】:2013-12-12 03:56:18
【问题描述】:

如何进行 url 重写以包含 www。并且不会导致无限循环问题?我有 url 重定向的问题。我需要确保 www.被添加到 url。 我意识到这必须在 .htaccess 中完成,经过一些研究和阅读,我认为我需要的代码是

RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.co.uk [NC]
RewriteRule ^(.*)$ http://www.example.co.uk/$1 [R=301,L]

这是一个 joomla 网站,因此该部分之后是 joomla sef 部分

## Begin - Joomla! core SEF Section.
#
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
#
# If the requested path and file is not /index.php and the request
# has not already been internally rewritten to the index.php script
RewriteCond %{REQUEST_URI} !^/index\.php
# and the request is for something within the component folder,
# or for the site root, or for an extensionless URL, or the
# requested URL ends with one of the listed extensions
RewriteCond %{REQUEST_URI} /component/|(/[^.]*|\.(php|html?|feed|pdf|vcf|raw))$ [NC]
# and the requested path and file doesn't directly match a physical file
RewriteCond %{REQUEST_FILENAME} !-f
# and the requested path and file doesn't directly match a physical folder
RewriteCond %{REQUEST_FILENAME} !-d
# internally rewrite the request to the index.php script
RewriteRule .* index.php [L]
#
## End - Joomla! core SEF Section.

如果我使用这个 Firefox 会警告我:

The page isn't redirecting properly

Firefox has detected that the server is redirecting the request for this address in a way that will never complete.

IE 找不到页面 如果我删除重写行,我会得到页面,但 url 会被重写为没有 www 的页面

我怎样才能强制 www.在网址中?

【问题讨论】:

    标签: .htaccess mod-rewrite joomla


    【解决方案1】:

    似乎重写规则确实有效,我发现 plesk 面板有一个域选项可以强制它们为 www。或非 www。这可能意味着 .htaccess 和主机的域设置之间存在冲突。这意味着该 url 永远不会被解析。

    当我将控制面板更改为无时,重写规则按预期工作。

    【讨论】:

      猜你喜欢
      • 2013-06-25
      • 2019-04-01
      • 2015-10-25
      • 2017-08-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-21
      • 2019-09-16
      相关资源
      最近更新 更多