我正在尝试将www.example.org.uk重定向到example.org.uk/subdirectory,然后隐藏子目录 - 所以它只在地址栏上显示www.example.org.uk。
这是我使用的原始代码(来自https://my.bluehost.com/cgi/help/347):
# BlueHost.com
# .htaccess main domain to subdirectory redirect
# Do not change this line.
RewriteEngine on
# Change example.com to be your main domain.
RewriteCond %{HTTP_HOST} ^(www.)?example.org.uk$
# Change 'subdirectory' to be the directory you will use for your main domain.
RewriteCond %{REQUEST_URI} !^/subdirectory/
# Don't change the following two lines.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Change 'subdirectory' to be the directory you will use for your main domain.
RewriteRule ^(.*)$ /subdirectory/$1
# Change example.com to be your main domain again.
# Change 'subdirectory' to be the directory you will use for your main domain
# followed by / then the main file for your site, index.php, index.html, etc.
RewriteCond %{HTTP_HOST} ^(www.)?example.org.uk$
RewriteRule ^(/)?$ subdirectory/index.php [L]
问题是这些代码都不起作用。
搜索Stackoverflow并使用建议后 - 这是当前代码:
Options +FollowSymLinks -Multiviews
<IfModule mod_rewrite.c>
# BlueHost.com
# .htaccess main domain to subdirectory redirect
# Do not change this line.
RewriteEngine on
# Change example.com to be your main domain.
RewriteCond %{HTTP_HOST} ^(www.)?grampianyoga.org.uk$
# Change 'subdirectory' to be the directory you will use for your main domain.
RewriteCond %{REQUEST_URI} !^/gya2/
# Don't change the following two lines.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Change 'subdirectory' to be the directory you will use for your main domain.
RewriteRule ^(.*)$ /gya2/$1
# Change example.com to be your main domain again.
# Change 'subdirectory' to be the directory you will use for your main domain
# followed by / then the main file for your site, index.php, index.html, etc.
RewriteCond %{HTTP_HOST} ^(www.)?grampianyoga.org.uk$
RewriteRule ^(/)?$ gya2/index.php [L]</IfModule>
不幸的是会显示内部错误,错误文件指出:[Wed Mar 26 14:22:35 2014] [9566783] [core:alert] [client 97.74.104.6:60525] /var/chroot/home/content/83/9566783/html/.htaccess: RewriteRule: bad flag delimiters
我正在使用GoDaddy,我相信他们有自己的设置。有没有人有什么建议?尝试了支持,显然他们 无法帮助编写脚本。
答案 0 :(得分:2)
我会更改行
RewriteCond %{REQUEST_URI} !^/subdirectory/
到
RewriteCond %{REQUEST_URI} !^/subdirectory/?
以便尾随/ 可选。如果您碰巧提供现有文件或目录,则不会触发带有 -f 和 -d 检查的代码。假设没有,
RewriteRule ^(.*)$ /subdirectory/$1
应该静默地将访问者发送到子目录(在现有URI之前插入 /子目录)。
我不知道为什么最后两行在那里。如果你关闭尾随/要求(如上所述),它们可能已被处理。尝试将它们评论出来(使用#)。
如果它仍然不起作用,GoDaddy的设置可能会有所不同。你应该讨论你正在尝试用他们的技术支持做什么。
更新:最新.htaccess的修改版
Options +FollowSymLinks -Multiviews
<IfModule mod_rewrite.c>
# BlueHost.com
# .htaccess main domain to subdirectory redirect
# Do not change this line.
RewriteEngine on
# Change example.com to be your main domain.
RewriteCond %{HTTP_HOST} ^(www\.)?grampianyoga\.org\.uk$
# Change 'subdirectory' to be the directory you will use for your main domain.
RewriteCond %{REQUEST_URI} !^/gya2
RewriteRule ^(.*)$ /gya2/$1 [L]
</IfModule>
RewriteCond %{HTTP_HOST} ^(www\.)?grampianyoga\.org\.uk$
行可能不必要(但无害),除非您正在使用托管域名,子域名,附加域名等。