【问题标题】:htaccess proper redirect with trailing slashhtaccess 带有斜杠的正确重定向
【发布时间】:2015-06-19 02:58:21
【问题描述】:

美好的一天!

当有这样的 GET 请求时,我想通过 htaccess 进行正确的重定向:

example.org/directory/page/

应该给出example.org/page.php

我的 htaccess 只允许重定向这种请求

example.org/directory/page

我使用这个配置

#remove extension
RewriteRule ^([^\.]+)$ $1.php [NC,L]
#remove directory
RewriteRule ^directory/(.*)$ /$1 [L]

感谢您的关注!

【问题讨论】:

  • 当你想服务example.org/directory/page.php时为什么需要RewriteRule ^directory/(.*)$ /$1 [L]规则?
  • 不好意思,错了,我编辑了

标签: regex apache .htaccess mod-rewrite clean-urls


【解决方案1】:

重新排列您的规则并调整.php 添加规则:

#remove directory
RewriteRule ^directory/(.*)$ /$1 [L]

#remove extension
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f [NC]
RewriteRule ^([^.]+)/?$ $1.php [L]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-22
    • 1970-01-01
    • 1970-01-01
    • 2014-06-22
    相关资源
    最近更新 更多