【发布时间】: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