简体   繁体   English

htaccess-从网址中删除“ index.php”并重定向至排除

[英]htaccess - remove “index.php” from URL and redirect with exclusion

I have read a lot of answers on this site, but didn't find a working example. 我已经在该站点上阅读了很多答案,但是没有找到有效的示例。 Therefore, I decided to ask my question. 因此,我决定问我的问题。

How can I make a redirect from a file (index.php(.htm /.html / etc.) with exclusion? 如何排除文件重定向(index.php(.htm /.html /等)?

For example, I have a link #1: "/dir1/some-text_index.php" and link #2: /dir1/index.php. 例如,我有一个链接#1:“ / dir1 / some-text_index.php”和一个链接#2:/dir1/index.php。 What rule should be set to link #1 - redirect doesn't happen, and link #2 occurred redirect, ie: 应该为链接#1设置什么规则-不会发生重定向,而链接#2发生了重定向,即:

/dir1/some-text_index.php -> /dir1/some-text_index.php - nothing to do
/dir1/index.php -> /dir1/ - redirect

and more examples: 和更多示例:

/dir1/some-text_index.php/dir2 -> /dir1/some-text_index.php/dir2 - nothing to do
/dir1/index.php/dir2 -> /dir1/dir2 - redirect
/dir1/some-text_index.php/dir2/?param=value -> /dir1/some-text_index.php/dir2/?param=value - nothing to do
/dir1/index.php/dir2/?param=value -> /dir1/dir2/?param=value - redirect

Thanks all for yours attention. 谢谢大家的关注。

You can use this rule in your root .htaccess: 您可以在根.htaccess中使用此规则:

RewriteEngine On

RewriteCond %{THE_REQUEST} /index\.php [NC]
RewriteRule ^(.*?)index\.php(?:/(.*))?$ /$1$2 [L,R=302,NC,NE]

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

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