我正在尝试创建一个看起来像http://localhost/slugs/this-is-my-first-slug-post
但我有http://localhost/slugs/news.php?newsheadline=this-is-my-first-slug-post
我有一个带有此代码的htaccess文件,但它似乎无法正常工作。
RewriteEngine On
RewriteRule ^[A-Za-z-]+/([A-Za-z0-9-]+)/?$ news.php?newsheadline=$1 [NC,L]
答案 0 :(得分:0)
您可以使用此规则:
RewriteEngine On
RewriteBase /slugs/
RewriteCond %{THE_REQUEST} /news\.php\?newsheadline=([^\s&]+) [NC]
RewriteRule ^ %1? [R=302,L,NE]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([\w-]+)/?$ news.php?newsheadline=$1 [QSA,L]