htaccess的重写规则麻烦重写、麻烦、规则、htaccess

2023-09-02 00:59:59 作者:那回忆抹掉的伤︶ㄣ

我猜这个问题已经被问了很多次,但我无法找到一个便叫给我我所需要的。

I am guessing this question has been asked many times, but i could not find one that would perhaps give me what I need.

所以..我可以通过以下网址的访问脚本:

So.. I can access the scripts by the following url's:

http://website.com/index.php/hello/world
http://website.com/hello/world

俩去的的index.php 的其中分析输入(你好/世界在这个例子中)。

Both go to index.php which parses the input (hello/world in this example).

这是我的的.htaccess 的:

<IfModule mod_rewrite.c>
Options +FollowSymlinks

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) index.php?path=$1&%{QUERY_STRING} [L]
</IfModule>

不过。当网站被这样的访问:

However. When the site is accessed like this:

http://website.com/index.php/hello/world

在重写规则的输出类似如下的的index.php?路径=的index.php /你好/世界的

the RewriteRule outputs something similar to index.php?path=index.php/hello/world

我要删除的的index.php 的后的路径= 的在重写规则的

I want to remove that index.php after path= in the RewriteRule

推荐答案

的.htaccess 文件应该是这样的(注意新规则检查的index.php是URL的一部分):

Your .htaccess file should look like this (notice the new rule that checks if index.php is a part of url):

<IfModule mod_rewrite.c>
Options +FollowSymlinks

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^index.php/(.*)$ index.php?path=$1&%{QUERY_STRING} [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) index.php?path=$1&%{QUERY_STRING} [L]

</IfModule>