.htaccess RewriteRule键作为文件夹,然后是值

问题描述 投票:1回答:2

我正在尝试制作一个RewriteRule。

我有下一个网址'https://sample.com/post.php?post=ABC123',我试图用'https://sample.com/post/ABC123'重定向

我只做了一个规则,重定向没有'/ post /',只有值:

RewriteRule ^([a-zA-Z0-9-z\-]+)$ post.php?post=$1
RewriteRule ^([a-zA-Z0-9-z\-]+)/$ post.php?post=$1

我如何制定第一条规则?

php .htaccess
2个回答
1
投票

您可以将此规则用作第一条规则:

Options -MultiViews
RewriteEngine On

RewriteRule ^post/([\w-]+)/?$ post.php?post=$1 [L,QSA,NC]

# other rules go below

0
投票

试试这个

Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)\/$ $1.php [NC]

RewriteRule ^post/([0-9]+)$ post.php?post=$1[QSA,L]
© www.soinside.com 2019 - 2024. All rights reserved.