[英]htaccess redirect from index.php to / only in specific folder
我想在我的 htaccess 文件中创建重定向。 从带有 index.php 的 url 到没有 index.php 的页面,但仅限于一个特定的文件夹“目录”。
例如:
从/catalog/some_folder/index.php
到/catalog/some_folder/
/catalog/some_folder/index.php
/catalog/some_folder/
或
从/catalog/some_folder/etc/index.php
到/catalog/some_folder/etc/
/catalog/some_folder/etc/index.php
/catalog/some_folder/etc/
像这样的 URL /catalog2/some_folder/index.php
不必重定向
我尝试添加这些行(本地主机,因为它是 xampp):
RewriteCond %{REQUEST_URI} /catalog/+[^\.]+index.php$
RewriteRule ^index\.php$ localhost/$1 [R=301,L]
但这没有用。 我怎样才能强迫它正常工作?
您可以在 root .htaccess 中使用此规则:
# remove index.php
RewriteCond %{THE_REQUEST} /index\.php [NC]
RewriteRule ^(catalog/.+)index\.php$ /$1 [L,R=302,NC,NE]
RewriteCond %{REQUEST_URI} /index.php
RewriteRule ^(.*)index\.(php)$ https://%{SERVER_NAME}/$1 [R=301,L]
如果需要把地址末尾的“index.php”全部去掉
删除 index.php:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]
请记住,您需要激活 mod_rewrite。
RewriteEngine On
RewriteCond %{THE_REQUEST} (?:/[^/]*)*/index\.php[?#\ ]
RewriteRule .* %{REQUEST_URI}/../ [L,R=301]
对我来说,这是可行的,上面的解决方案是将我发送到一个文件夹上一层。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.