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

时间:2018-09-05 10:53:32

标签: php .htaccess

我正在尝试制作一个RewriteRule。

我有下一个URL'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

如何制定第一个规则?

2 个答案:

答案 0 :(得分:1)

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

Options -MultiViews
RewriteEngine On

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

# other rules go below

答案 1 :(得分: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]