【问题标题】:Per-server rewriterules not working每服务器重写规则不起作用
【发布时间】:2012-05-29 01:25:36
【问题描述】:

我在/etc/apache2/openpanel.d/www.example.com.conf 中有一个 VirtualHost 指令:

<VirtualHost *:80>
   ServerAdmin        "jon@example.com"
   DocumentRoot       /home/openpanel-admin/sites/www.example.com/public_html
   ServerName         www.example.com
   ServerAlias        example.com
   <Directory /home/openpanel-admin/sites/www.example.com/public_html>
   AllowOverride      All
   Allow from all
   </Directory>
   Include /etc/apache2/openpanel.d//www.example.com.inc/[^.#]*
   Include /etc/apache2/openpanel.d//global.inc
</VirtualHost>

我在/etc/apache2/openpanel.d/www.example.com.inc/RewriteRules中有以下内容

<Directory /home/openpanel-admin/sites/www.stallfinder.com/public_html>
        Options +FollowSymlinks
        RewriteEngine On

        RewriteRule agricultural-show-c780.html /search/event/agricultural-shows/1/ [R=301,L]
        RewriteRule antique-fair-c596.html /search/event/antique-and-collectors-fairs/1/ [R=301,L]
        RewriteRule baby-and-toddler-fairs-c896.html /search/event/baby-and-toddler-fairs/1/ [R=301,L]
        RewriteRule book-fair-c631.html /search/event/book-fairs/1/ [R=301,L]

        # etc... there are ~3000 of these
</Directory>

我在/home/openpanel-admin/sites/www.example.com/public_html 中有一个.htaccess 文件:

Options +FollowSymlinks

RewriteEngine On
RewriteBase /

# Search pages
RewriteRule ^search/(stallholder|event)/?$ /find-$1.php [L]
RewriteRule ^search/(stallholder|event)/([^/]+)/([0-9]+)/? /$1.php?name=$2&id=$3 [L]

但包含文件 (RewriteRules) 中的 RewriteRules 似乎没有被解析/使用。

该文件被包含在内,因为我可以在其中放置不允许的内容,并且 apache 将无法加载配置文件,但是如果我打开 Apache 重定向日志记录,那么我只会看到 [perdir] 行,就好像所有的 RewriteRules我在 RewriteRules 中包含未处理。

global.inc 文件为空,我的.htaccess 文件中的 RewriteRules 工作正常。

知道我做错了什么吗?

【问题讨论】:

  • 不是 100% 确定这是否真的有效(无权访问工作的 Apache 实例来检查),但是...尝试将 RewriteOptions 指令添加到您的 .htaccess 中 -- httpd.apache.org/docs/current/mod/…
  • @LazyOne 天才!这工作,非常感谢!随意添加它作为答案,我会接受它。

标签: apache .htaccess mod-rewrite


【解决方案1】:

尝试将 RewriteOptions 指令添加到您的 .htaccess 中,以允许在父(上)级别执行重写规则。

http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewriteoptions

【讨论】:

    猜你喜欢
    • 2011-09-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-22
    • 1970-01-01
    • 2013-07-06
    相关资源
    最近更新 更多