如何重写URL?

时间:2015-08-18 07:32:12

标签: .htaccess mod-rewrite url-rewriting

如何在php中将网址http://www.kreativemines.com/blogpost.php/?post_slug=search-engine-optimization更改为http://www.kreativemines.com/blog/search-engine-optimization

我已经从.htaccess文件中使用此规则,但没有解决方案。

RewriteEngine On
RewriteRule ^blog/([a-zA-Z0-9_-]+)$ blogpost.php/?post_slug=$1

1 个答案:

答案 0 :(得分:0)

这应该有效:

RewriteEngine On
RewriteCond %{THE_RERUEST} /blogpost\.php/\?post_slug=([^&\s]+) [NC] 
RewriteRule ^ blog/%1? [NC,R,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^blog/([^/]+)/?$ /blogpost.php/?post_slug=$1 [QSA,L,NC]