【问题标题】:How to remove file extension from Mod_rewrite?如何从 Mod_rewrite 中删除文件扩展名?
【发布时间】:2019-07-10 00:01:12
【问题描述】:

我想制作漂亮的网址:

 http://www.example.com/search-destroy?id=nameOfCharacter

我有这个 mod_rewrite:

 RewriteRule ^search-destroy/([^/]*)$ /search-destroy?id=$1 [L,QSA]

生成这个 url:

 http://www.example.com/search-destroy/nameOfCharacter.php

我想在这里省略 .php 扩展名,mod_rewrite 看起来如何?

【问题讨论】:

标签: apache .htaccess mod-rewrite friendly-url


【解决方案1】:

在类似的情况下,我做了如下所示的事情

<IfModule mod_rewrite.c>
        RewriteEngine On  
        RewriteRule ^search_destroy/([^/.]+)?$ your_php.php?search_destroy=$1 [L]
</IfModule>

有一些变化。

1) 一个常见的 php 脚本 - “your_php.php”

在 your_php.php - 你应该如下所示处理它

if(isset($_GET['search_destroy'])) {
   // YOUR CODE BASED ON YOUR DYNAMIC id

}

希望对你有帮助

谢谢

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-06-29
    • 2013-10-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-14
    • 1970-01-01
    • 2020-03-25
    相关资源
    最近更新 更多