我在重写URL时遇到了一些实际问题,任何帮助都将受到大力赞赏。使用旧的.htaccess规则重写网址
我有一个名为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进行预览。 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 [email protected]
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>
我一直在试图整个下午排序了这一点,我看不出有什么不对!任何人都可以将我指向正确的方向吗?
对于从哪里开始进行故障排除,我确实感到茫然。我打开了重写日志记录,但没有出现在日志文件中。
我在使用PHP 5.5.10的Ubuntu 12.04上运行Apache 2.4.9。
首先,代替使用'&%{QUERY_STRING}'只需将[L]更改为[L,QSA],并且apache将追加查询字符串,然后在正则表达式中使用点。你是指'^ share /([^ /] +)/?$'而不是'^ share /([^/\.]+)/?$'?如果只有共享的数值,你也可以做'^ share /([0-9] +)/?$' – Bor691