我们在public_html
的新目录中有一个新网站,如下图黄色所示。
我们需要向new_site/.htaccess
添加规则以满足以下三条规则:
.php
/
(不包括.jpg,.png,...)/index.php?
。
最有可能的是,这就是我试图提出的问题:
目前,
domain.com/ns/abc.php
domain.com/ns/abc_abc.php
domain.com/ns/index.php?/abc
domain.com/ns/abc/index.php?/abc
domain.com/ns/abc/abc/index.php?/abc/123
domain.com/ns/abc/abc/index.php?/abc/abc/123/123
要
domain.com/ns/abc/
domain.com/ns/abc_abc/
domain.com/ns/abc/
domain.com/ns/abc/abc/
domain.com/ns/abc/abc/abc/123/
domain.com/ns/abc/abc/abc/abc/123/123/
我们还尝试了一些以前发布的规则来执行此任务。如
Options +FollowSymlinks -MultiViews
RewriteEngine on
RewriteBase /ns
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1 [L,QSA]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s(.*)/index\.php [NC]
RewriteRule ^ %1 [R=301,L]
上述代码帮助我们删除了index.php
。但是,我们无法弄明白如何删除/index.php?
。
任何评论/建议表示赞赏!谢谢!
答案 0 :(得分:1)
以下内容应该可以实现这一目标:
RewriteEngine On
RewriteRule ^ns/(.*)/(.*)/index.php/(.*)/(.*)/(.*)/(.*)$ /ns/$1/$2/$3/$4/$5/$6/ [R,L]
RewriteRule ^ns/(.*)/(.*)/index.php/(.*)/(.*)$ /ns/$1/$2/$3/$4/ [R,L]
RewriteRule ^ns/(.*)/index.php/(.*)$ /ns/$1/$2/ [R,L]
RewriteRule ^ns/index.php/(.*)$ /ns/$1/ [R,L]
RewriteRule ^ns/(.*).php$ /ns/$1/ [R,L]
编辑: 第二次尝试:
RewriteEngine On
RewriteCond %{THE_REQUEST} ^(GET|POST)\ /ns/(.*)/(.*)/index\.php\?/(.*)\ HTTP
RewriteRule ^ /ns/%2/%3/%4\? [R,L]
RewriteCond %{THE_REQUEST} ^(GET|POST)\ /ns/(.*)/index\.php\?/(.*)\ HTTP
RewriteRule ^ /ns/%2/%3\? [R,L]
RewriteCond %{THE_REQUEST} ^(GET|POST)\ /ns/index\.php\?/(.*)\ HTTP
RewriteRule ^ /ns/%2\? [R,L]
RewriteRule ^ns/(.*).php$ /ns/$1/ [R,L]