从url中删除.php扩展名

时间:2012-03-16 11:42:27

标签: .htaccess url-rewriting

我需要通过重写url从url中删除.php扩展名和查询字符串 我知道这可以在.htaccess文件中完成 到目前为止,我在.htaccess文件中有这个

            RewriteEngine on
            DirectoryIndex Home.html

            RewriteCond %{REQUEST_FILENAME}.php -f
            RewriteCond %{REQUEST_URI} !/$
            RewriteRule (.*) $1\.php [L]

            # if a directory or a file exists, use it directly
            RewriteCond %{REQUEST_FILENAME} !-f
            RewriteCond %{REQUEST_FILENAME} !-d
            # otherwise forward it to index.html
            RewriteRule .* Home.html

现在的网址 example.com/blog.php?post=12&comment=3 可以访问 example.com/blog.php/post/12/comment/3 但我也想删除.php扩展名 这必须通过这个网址访问 example.com/blog/post/13/comment/3

任何帮助?

提前谢谢。

1 个答案:

答案 0 :(得分:1)

/

之后搜索除之外的所有内容
RewriteRule ^(([^/]+/)*[^.]+)$ /$1.php [L]
相关问题