【问题标题】:URL Rewriting don't work in my apache2URL 重写在我的 apache2 中不起作用
【发布时间】:2013-09-12 14:51:02
【问题描述】:

我的 apache2 有问题,url 重写不起作用,我不知道为什么...

在我的 phpinfo() 中,我有:

Loaded Modules: mod_rewrite 

我的 .htaccess:

Options +FollowSymLinks
RewriteEngine on
RewriteRule ^test\.html$ /test.php [L]

我的 Apache 配置:

<VirtualHost>
        ServerAdmin mail@gmail.com
        ServerName www.site.com
        ServerAlias site.com
        DocumentRoot /var/www/site.com/

        <Directory />
                Options FollowSymLinks
                AllowOverride All
        </Directory>
        <Directory /var/www/site.com/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                Order allow,deny
                allow from all
        </Directory>

        ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
        <Directory "/usr/lib/cgi-bin">
                AllowOverride All
                Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
                Order allow,deny
                Allow from all
        </Directory>

        ErrorLog /var/log/apache2/error.log

        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel warn

        CustomLog /var/log/apache2/access.log combined

    Alias /doc/ "/usr/share/doc/"
    <Directory "/usr/share/doc/">
        Options Indexes MultiViews FollowSymLinks
        AllowOverride All
        Order deny,allow
        Deny from all
        Allow from 127.0.0.0/255.0.0.0 ::1/128
    </Directory>

</VirtualHost>

我认为我的配置是正确的,但我真的不知道为什么我的重写不起作用......你有什么想法吗?

非常感谢!

【问题讨论】:

    标签: php apache url url-rewriting


    【解决方案1】:

    对于这个特定的规则:

    RewriteRule ^test\.html$ /test.php [L]
    

    Mod_negotiation 将尝试为您处理它。如果你想让它工作,你想转Multiviews off

    Options -Multiviews
    

    在您的 htaccess 文件顶部,或将其从您的 &lt;Directory&gt; 容器中删除:

        <Directory /var/www/site.com/>
                Options Indexes FollowSymLinks
                AllowOverride All
                Order allow,deny
                allow from all
        </Directory>
    

    【讨论】:

    • 谢谢乔恩·林。我删除了我的虚拟主机的“Multiviews”字样。但是当我转到我的页面时:site.com/test.php,url总是这样(site.com/test.php)...我已经重新启动了服务(service apache2 restart),但是url重写不起作用...
    • @Dimi 您的规则采用 URL /test.html 并在内部将其重写为 /test.php,而不是相反。如果您请求 /test.php,则该规则不会执行任何操作。
    猜你喜欢
    • 2013-07-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-11
    • 2014-10-10
    • 1970-01-01
    • 2011-08-08
    • 2013-10-03
    相关资源
    最近更新 更多