重定向HTML页面扩展到PHP扩展与参数使用htaccess不工作


redirecting html page extension to php extension with parameters using htaccess not working

这就是我想要实现的。我想重定向像这样的

http://www.example.com/news/news-seo-title-with-unicode-maybe.html

http://www.example.com/news.php?seo_url=news-seo-title-with-unicode-maybe.php

这是我在我的htaccess文件

中写的内容
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/(.*)'.html$ $1.php?seo_url=$2 [L]

我被重定向到news.php,但没有在$_GET变量。我的htaccess代码有什么错误吗?

您可以使用:

Options +FollowSymlinks -MultiViews
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^.]+)'.html$ $1.php?seo_url=$2 [L,NC,QSA]

选项MultiViews由运行在mod_rewrite之前的Apache's content negotiation module使用,并使Apache服务器匹配文件的扩展名。所以/file可以在URL中,但它将服务于/file.php