【问题标题】:mod Rewrite : Hide php extension & replace variable name by slashmod Rewrite:隐藏 php 扩展名并用斜杠替换变量名
【发布时间】:2013-08-08 16:42:49
【问题描述】:

需要帮助,这是基本的 Mod-Rewrite。但我很困惑

我当前的网址:

http://example.com/category.php?fn=accounting-tax

想要这样:

 http://example.com/category/accounting-tax

只有 Apache Mod-Rewrite,请不要使用 PHP

更新:

没有 PHP 可以吗?

谢谢

【问题讨论】:

标签: mod-rewrite apache2 cpanel


【解决方案1】:

将此添加到您的网络根/ 中的.htaccess

RewriteEngine on
RewriteBase /

RewriteCond %{QUERY_STRING} (^|&)fn=(.*)(&|$)
RewriteRule ^category\.php$ category/%2 [NC,L]

假设,你的意思是

/category.php?fn=accounting-tax 应该带你到/category/accounting-tax

不显示在地址栏上。如果您想要外部重定向,请改用[R=301,NC,L]

【讨论】:

  • 您能描述一下您输入的网址以及您被重定向到的内容吗?
  • 只想用“/”替换“.php?fn="部分
  • 请再看一遍问题
  • 没有。任何额外的?params 都应自动附加为accounting-tax?params
【解决方案2】:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^category/([a-z0-9\-]+)/item/?$ /category.php?id=$1
</IfModule>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-20
    • 2011-07-28
    • 1970-01-01
    • 2011-03-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多