【问题标题】:Rewrite a path with htaccess taking parameters too使用带参数的 htaccess 重写路径
【发布时间】:2021-03-03 02:04:35
【问题描述】:

我想使用 htaccess mod rewrite 重写我的网站的路径,也接受参数。所以,我希望我的网站执行如下操作:

mysite.com/chat.php?a=text&b=1&c=2&d=text

当我写下这条路径时:

mysite.com/chat/text/1/2/text

我该怎么做?

这是我现在的 htaccess,但它不起作用:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^chat/([a-z]+)/([0-9]+)/([0-9]+)/([a-z]+)$ chat.php?n=$1&c=$2&s=$3&b=$4 [QSA]

【问题讨论】:

  • 请在您的问题中发布您的 htaccess 文件,谢谢。

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


【解决方案1】:

您能否尝试仅使用所示示例进行以下、编写和测试。 请确保在测试 URL 之前清除浏览器缓存。

RewriteEngine ON
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)/([^/]*)/([^/]*)/([^/]*)$ $1.php?a=$2&b=$3&c=$4&d=$5 [L]


或查找专门以chat 开头的网址,请尝试关注。请确保您使用上述规则或以下规则集,一次只使用一个。

RewriteEngine ON
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(chat)/([^/]*)/([^/]*)/([^/]*)$ $1.php?a=$2&b=$3&c=$4&d=$5 [NC,L]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-16
    • 2021-05-08
    • 2013-01-25
    • 2021-02-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多