gpt4 book ai didi

.htaccess 在删除 php 扩展和内部重定向时抛出文件夹

转载 作者:行者123 更新时间:2023-12-01 12:45:20 25 4
gpt4 key购买 nike

我是按照这个问题做的( Redirect .php urls to urls without extension )但这会将我带到根文件夹。

RewriteEngine On
# browser requests PHP
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^\ ]+)\.php
RewriteRule ^/?(.*)\.php$ /$1 [L,R=301]
# check to see if the request is for a PHP file:
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^/?(.*)$ /$1.php [L]

例如。我的原始网址 http://www.website.com/products/abc.php
重定向后,它会将我发送到 http://www.website.com/abc

最佳答案

这是一个可以处理子文件夹的通用规则

Options -MultiViews
RewriteEngine On

# browser requests PHP
RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(.+/)?([^/\s\?&]+)\.php
RewriteRule ^ /%1%2 [L,R=301]

# check to see if the request is for a PHP file:
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.+)$ /$1.php [L]

关于.htaccess 在删除 php 扩展和内部重定向时抛出文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51263300/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com