【问题标题】:Apache mod_rewrite never rewrite for existing directory except directory is certain directory?Apache mod_rewrite 永远不会重写现有目录,除非目录是某个目录?
【发布时间】:2013-01-05 05:31:51
【问题描述】:

网站http://www.example.com/ 在CMS 上运行,一切都按照.htaccess 中设置的规则进行。访问http://www.example.com/ 时,根据用户的语言设置,用户将被重定向到以下路径之一:

http://www.example.com/en/
http://www.example.com/fr/

/en//fr/ 目录实际上并不存在,它们由 CMS 处理。

我正在向站点添加一个新部分 (investors/),但现在不希望它通过 CMS,但我不希望用户注意到它。

原始 .htaccess 文件有以下几行:

# never rewrite for existing files, directories and links
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
# rewrite everything else to index.php
RewriteRule .* index.php [L]

如果请求的路径以/en/investors//fr/investors/ 开头,我设法让它不通过CMS:

# never rewrite for existing files, directories and links
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
# rewrite everything else to index.php
# except investors' section
RewriteRule ^(?!\/en\/investors|\/fr\/investors).+ index.php [L]

我将/en/investors//fr/investors/ 目录上传到服务器上,它们工作正常,但现在主页已损坏,因为/en//fr/ 目录现在存在。如何向该规则添加例外?

【问题讨论】:

    标签: apache mod-rewrite apache2


    【解决方案1】:

    简单地添加另一个规则来覆盖 2 个目录,例如

    RewriteRule ^(en|fr)/?$ index.php [L]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-06-15
      • 1970-01-01
      • 2016-08-31
      • 1970-01-01
      • 2012-06-26
      • 2013-01-30
      • 2011-05-30
      • 1970-01-01
      相关资源
      最近更新 更多