重写htaccess导致无限循环?

时间:2013-11-26 19:56:19

标签: .htaccess mod-rewrite joomla

如何将网址重写为包含www。并没有导致无限循环问题?我有网址重定向的问题。我需要确保www。被添加到网址。 我意识到这必须在.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无法找到该页面 如果我删除了重写行,我会得到页面,但是网址被重写为没有www

的网址

我如何强制使用www。在网址?

1 个答案:

答案 0 :(得分:1)

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

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