【问题标题】:Remove .php extension from url从 url 中删除 .php 扩展名
【发布时间】:2012-03-16 11:42:26
【问题描述】:

我需要通过重写 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 扩展名 这必须可以通过这个 url 访问 example.com/blog/post/13/comment/3

有什么帮助吗?

提前谢谢你。

【问题讨论】:

标签: .htaccess url-rewriting


【解决方案1】:

/

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

【讨论】:

  • 我在 XAMPP 上试过它工作。你能试试这个规则吗RedirectMatch ^(([^/]+/)*[^.]+)$ http://www.google.com?q=$1.php
猜你喜欢
  • 2012-08-27
  • 1970-01-01
  • 2022-01-21
  • 1970-01-01
  • 2023-04-05
  • 1970-01-01
  • 2020-08-11
相关资源
最近更新 更多