Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用旧的.htaccess规则重写URL_Php_Apache_.htaccess_Mod Rewrite_Url Rewriting - Fatal编程技术网

Php 使用旧的.htaccess规则重写URL

Php 使用旧的.htaccess规则重写URL,php,apache,.htaccess,mod-rewrite,url-rewriting,Php,Apache,.htaccess,Mod Rewrite,Url Rewriting,我有一些真正的问题,重新编写网址和任何帮助将不胜感激 我有一个名为share.php的php文件和一个包含以下规则的.htaccess文件: RewriteRule ^share/([^/\.]+)/?$ share.php?variable=$1&%{QUERY_STRING} [L] 如果导航到domain.com/share/123456,将加载share.php页面,但$\u GET['variable']中没有值。 我在.htaccess文件中有一些其他重写规则,我认为它们可

我有一些真正的问题,重新编写网址和任何帮助将不胜感激

我有一个名为
share.php
的php文件和一个包含以下规则的.htaccess文件:

RewriteRule ^share/([^/\.]+)/?$ share.php?variable=$1&%{QUERY_STRING} [L]
如果导航到
domain.com/share/123456
,将加载
share.php
页面,但
$\u GET['variable']
中没有值。 我在.htaccess文件中有一些其他重写规则,我认为它们可能有问题,所以我删除了所有其他规则。我删除的规则之一是将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
(在
$\u 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>

服务器管理员webmaster@localhost
ServerName域名.com
ServerAlias www.domain.com
DocumentRoot/home/www/domain.com/public\u html
选项如下符号链接
允许超越所有
选项索引跟随符号链接多视图
允许超越所有
要求所有授权
ScriptAlias/cgi-bin//usr/lib/cgi-bin/
允许超越所有
选项+执行CGI-多视图+符号链接所有者匹配
要求所有授权
ErrorLog${APACHE_LOG_DIR}/error.LOG
#可能的值包括:调试、信息、通知、警告、错误、临界值、,
#警惕,埃默格。
日志级别警告
CustomLog${APACHE\u LOG\u DIR}/access.LOG组合
别名/doc/“/usr/share/doc/”
选项索引多视图跟随符号链接
允许超越所有
要求全部拒绝
允许从127.0.0.0/255.0.0.0::1/128开始
我整个下午都在想办法解决这个问题,但我就是看不出有什么不对!谁能给我指出正确的方向吗

我真的不知道从哪里开始解决这个问题。我打开了重写日志,但日志文件中没有显示任何内容


我正在使用PHP5.5.10在Ubuntu12.04上运行Apache 2.4.9。

在您的域配置中,启用了
mod\u协商的
MultiViews
选项。关于这些选项的讨论可能会有所帮助。它完全符合你描述的和你不想发生的事情。在评估重写规则之前会对其进行处理,因此它可能与您的问题有关

您可以通过从域配置中删除
MultiViews
选项或将以下行添加到
.htaccess
文件来禁用此行为:

Options -MultiViews


另外,您应该使用
QSA
标志(用于查询字符串追加),而不是手动追加
%{Query\u String}

首先,不要使用
&%{Query\u String}
只需将[L]更改为[L,QSA],apache将追加查询字符串,第二,正则表达式中的点是什么?你是说
^share/([^/]+)/?$
而不是
^share/([^/\.]+)/?$
?如果共享只有数值,您也可以执行
^share/([0-9]+)/?$
非常感谢!我准备把我的笔记本电脑扔出窗外!我将Options-MultiViews添加到域conf文件的目录部分,并用QSA替换了QUERY_字符串。现在一切都很好:)