简体   繁体   English

htaccess带有斜杠的正确重定向

[英]htaccess proper redirect with trailing slash

Good day! 美好的一天!

I want to make proper redirect by htaccess, when there is GET request like this: 当有这样的GET请求时,我想通过htaccess进行适当的重定向:

example.org/directory/page/

It should give example.org/page.php 它应该给出example.org/page.php

My htaccess lets only redirect this kind of request 我的htaccess只允许重定向此类请求

example.org/directory/page

I use this config 我使用这个配置

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

Thank you for attention! 感谢您的关注!

Reorder your rules and tweak .php adding rule: 重新排序规则并调整.php添加规则:

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM