[英]URL rewriting using old .htaccess rules
我在重写URL方面遇到了一些实际问题,任何帮助都将受到大力赞赏。
我有一个名为share.php
的php文件和一个包含以下规则的.htaccess文件:
RewriteRule ^share/([^/\.]+)/?$ share.php?variable=$1&%{QUERY_STRING} [L]
如果我导航到domain.com/share/123456
,则会加载share.php
页面,但$_GET['variable']
没有值。 我在.htaccess文件中有一些其他的重写规则,我认为它们可能存在问题,所以我删除了所有其他规则。 我删除的规则之一是rewriting domain.com/preview
为domain.com/preview.php
RewriteRule ^preview/?$ preview.php?&%{QUERY_STRING} [L]
然后我注意到,即使删除了所有其他规则,如果我导航到domain.com/preview,它仍会将URL重写为preview.php。
所以,我完全删除了.htaccess文件,重新启动了Apache,清除了Firefox中的缓存并再次测试了它。 即使.htaccess文件已被删除,规则仍然有效。 domain.com/preview
仍然重定向到domain.com/preview.php
和domain.com/share/123456
仍然重定向到domain.com/share.php
(在没有数据$_GET['variable']
2个域指向服务器,但任何.conf文件中都没有重写规则,并且不再有任何.htaccess文件。 我已经尝试将重写规则放在域的.conf文件中,但我遇到了同样的问题。
如果我运行phpinfo()
Modrewrite将显示为已加载的模块。 这是我的域名.conf文件:
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName domain.com
ServerAlias www.domain.com
DocumentRoot /home/www/domain.com/public_html
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /home/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride All
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride All
Require all denied
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
</VirtualHost>
我整个下午一直试图解决这个问题,我只是看不出有什么问题! 谁能指出我正确的方向?
我真的不知道从哪里开始排除故障。 我打开了重写日志记录,但日志文件中没有任何内容。
我在Ubuntu 12.04上使用PHP 5.5.10运行Apache 2.4.9。
在域配置中,启用了mod_negotiation
的MultiViews
选项。 关于这些选项的参考可能会有所帮助。 它完全符合您的描述以及您不希望发生的事情。 在评估重写规则之前进行处理,因此可能与您的问题有关。
您可以通过从域配置中删除MultiViews
选项或.htaccess
下行添加到.htaccess
文件来禁用此行为:
Options -MultiViews
此外,您应该使用QSA
标志(对于查询字符串追加 )而不是手动附加%{QUERY_STRING}
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.