我有以下HTAccess文件:
ErrorDocument 404 /index.php?name=404
RewriteEngine on
# Add www. to any link without it
RewriteCond %{HTTP_HOST} ^mydomain\.co.uk$
RewriteRule ^(.*)$ http://www.mydomain.co.uk/$1 [R=301,L]
# Set homepage
DirectoryIndex index.php
# Rewrite content pages
RewriteRule ^sub1/([A-Za-z0-9_-]*)/$ index.php?sub1=1&name=$1
RewriteRule ^sub2/([A-Za-z0-9_-]*)/$ index.php?sub2=1&name=$1
RewriteCond %{REQUEST_URI} !^/404/
RewriteRule ^([A-Za-z0-9_-]*)/$ index.php?name=$1
# Make the pages without .php work
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^([^/]+)/$ $1.php
# Forces a trailing slash to be added
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]
这已经逐渐增加了一些东西,我现在做了一个很小的改变,但是无法解决这个问题。
规则基本上是为了确保所有页面都有www并以/.
结尾大多数网页的格式为www.mydomain.co.uk/page/,实际上是mydomain.co.uk/index.php?name=page。有两个子域将一个额外的get参数传递给index.php。
问题是主页可以从www.mydomain.co.uk/或www.mydomain.co.uk/index/访问。
如何修改这些规则,以便用户输入www.mydomain.co.uk时重定向到www.mydomain.co.uk/index /?
答案 0 :(得分:1)
尝试在下面修改.htaccess
### Existing Rules
# Add www. to any link without it
RewriteCond %{HTTP_HOST} ^mydomain\.co.uk$
RewriteRule ^(.*)$ http://www.mydomain.co.uk/$1 [R=301,L]
##New Rules
#if request for www.mydomain.co.uk
RewriteCond %{HTTP_HOST} ^www\.mydomain\.co\.uk$
#and it is for the home page, then redirect to index
RewriteRule ^$ http://www.mydomain.co.uk/index/ [L,R=301]
##Other Existing rules go here