经过大量的搜索,我找到了一条非常好的线索,帮助我朝着目标迈出了重要的一步。现在一切都很顺利,除了以下几点:
在以下情况下,我需要重写或重定向到www.example.com/go404
:
www.example.com
www.example.com/
example.com
example.com/
当然,当他们打字时
www.example.com/subdomain
或example.com/subdomain
目前,我的.htaccess
代码添加了以下代码片段:
# This sends "just domain" visits to 404
RewriteCond %{HTTP_HOST} ^example.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/go404 [R=301,L]
# This one makes a NON WWW become a WWW
RewriteCond %{HTTP_HOST} ^example.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
# This strips the trailing slash
RewriteRule ^(.*)\/(\?.*)?$ $1$2 [R=301,L]
有人能告诉我如何设置条件,使它只允许域写没有尾随斜杠和/或子文件夹字符串?如上所述,这些应该重定向到404。
我试图让我们的Magento站点使用.htaccess
重写来响应如下表所示。不管出于什么原因,只有一些选项起作用(标记为“OK”)。其他的产生www.example.com
,我不想要(标记为“Fail”)。
| 当访客键入|(内部)结果应为:|
| - -|- -|
| www.example.com
| www.example.com/go404
(未通过)|
| www.example.com/
| www.example.com/go404
(未通过)|
| www.example.com/notfound
| www.example.com/go404
(正常)|
| www.example.com/subdomain
个|www.example.com/_subdomain
(正常)|
| www.example.com/subdomain/
| www.example.com/_subdomain
(正常)|
| x1米20英寸|www.example.com/admin
(正常)|
| example.com
| www.example.com/go404
(未通过)|
| example.com/notfound
| www.example.com/go404
(未通过)|
| example.com/
| www.example.com/go404
(未通过)|
| x1米28英寸1x| www.example.com/_subdomain
(未通过)|
| x1米30英寸|www.example.com/_subdomain
(正常)|
| x1米32英寸|www.example.com/admin
(未通过)|
为了让我们的根目录保持有序,所有的子域都是名为_subdomain的文件夹。访问者只需写上www.example.com/subdomain
,并在前面加上下划线。
备注:
- “notfound”是没有相应“_subdomain”文件夹的任何字符串
- “admin”是有效的例外:前面无下划线
- 正如你可以从上面的表格中看到的,所有没有“www”的地址都失败了。另外,我有两个具体的问题与“clean”域+带斜杠的clean域有关。
这是我完整的.htaccess
(我删除了评论,使它更短):
addhandler x-httpd-php5-cgi .php5
addhandler x-httpd-php5-cgi .php
addhandler x-httpd-php-cgi .php4
Options -MultiViews
DirectoryIndex index.php
<IfModule mod_php5.c>
php_value memory_limit 256M
php_value max_execution_time 18000
php_flag magic_quotes_gpc off
php_flag session.auto_start off
php_flag suhosin.session.cryptua off
php_flag zend.ze1_compatibility_mode Off
</IfModule>
<IfModule mod_security.c>
SecFilterEngine Off
SecFilterScanPOST Off
</IfModule>
<IfModule mod_deflate.c>
</IfModule>
<IfModule mod_ssl.c>
SSLOptions StdEnvVars
</IfModule>
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteRule ^api/([a-z][0-9a-z_]+)/?$ api.php?type=$1 [QSA,L]
RewriteRule ^api/rest api.php?type=rest [QSA,L]
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{REQUEST_METHOD} ^TRAC[EK]
RewriteRule .* - [L,R=405]
RewriteCond %{REQUEST_URI} !^/(media|skin|js)/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule .* index.php [L]
</IfModule>
AddDefaultCharset Off
<IfModule mod_expires.c>
ExpiresDefault "access plus 1 year"
</IfModule>
Order allow,deny
Allow from all
<Files RELEASE_NOTES.txt>
order allow,deny
deny from all
</Files>
RewriteCond %{HTTP_HOST} ^example\.com$
RewriteRule ^example\.com/(admin)$ www.example.com/$1 [L]
RewriteRule ^/(.*)$ www.example.com/_$1 [L]
RewriteRule ^www\.example\.com/(admin)$ www.example.com/$1 [L]
RewriteRule ^www\.example\.com/(.*)$ www.example.com/_$1
1条答案
按热度按时间htzpubme1#
我不知道你是怎么用那些重写规则来处理第三个案子的。它们不应该起作用。
下面是我将使用的方法: