【发布时间】:2014-09-05 02:32:18
【问题描述】:
我正在尝试在 .htaccess 文件中使用以下 Apache 重写规则来去除 URL 的尾部斜杠。我在各个论坛的多个主题中都看到了这个解决方案:
RewriteRule ^(.*)/$ $1 [L,R=301]
这是导致 URL 的原因
http://www.domain.com/widgets/
改写为
http://www.domain.com/usr/local/www/apache22/data/domain/widgets
RewriteRule 前面是一些显式的 301 重定向,后面是其他重写条件和规则,但即使它是 .htaccess 文件中的唯一语句,也会发生同样的事情。
这个问题发生在我的 linux 服务器和我的 XAMPP 服务器上。在 Windows 中,URL 被重写为
http://www.domain.com/C:/xampp/htdocs/domain/widgets
如果我从规则中删除“L”,则会在 apache 日志中记录 301,但不会发生重写。
这是该域的虚拟主机条目:
<VirtualHost X.X.X.X:80>
ServerAdmin admin@domain.com
DocumentRoot "/usr/local/www/apache22/data/domain"
ServerName www.domain.com
ErrorLog "/var/log/apache22/domain-error.log"
CustomLog "/var/log/apache22/domain-access.log" combined
<Directory /usr/local/www/apache22/data/domain>
AllowOverride FileInfo
</Directory>
<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault "access plus 1 week"
ExpiresByType text/html "access plus 1 week"
ExpiresByType image/gif "access plus 1 week"
ExpiresByType image/jpeg "access plus 1 week"
ExpiresByType image/png "access plus 1 week"
ExpiresByType text/css "access plus 1 week"
ExpiresByType text/javascript "access plus 1 week"
ExpiresByType application/x-javascript "access plus 1 week"
ExpiresByType text/xml "access plus 1 week"
</IfModule>
</VirtualHost>
对可能发生的事情有什么建议吗?
【问题讨论】:
-
你找到解决办法了吗?
标签: linux apache .htaccess url mod-rewrite