使用.htaccess更改URL中的index.php

时间:2015-07-30 07:35:16

标签: php regex .htaccess mod-rewrite url-rewriting

我想在网址中替换index.php

我的网址示例:

http://example.com/index.php/blog/foo

我需要:

http://example.com/my.php/blog/foo
or
http://example.com/name/blog/foo
http://example.com/shop/blog/foo
...

2 个答案:

答案 0 :(得分:1)

您可以在DOCUMENT_ROOT/.htaccess文件中使用此代码:

RewriteEngine On
RewriteBase /

RewriteRule ^[^/]+/(blog/.+)$ index.php/$1 [L,NC]

答案 1 :(得分:0)

尝试使用sed

echo "http://example.com/index.php/blog/foo" | sed 's/index.php/my.php/'