如何使用htaccess更改我们的网站URL

时间:2015-10-27 11:37:22

标签: php apache .htaccess mod-rewrite url-rewriting

我是PHP的新手,因此我使用.htacess使用网址重定向遇到了一些问题。

我的网址页面如下所示:http://domain.com/blog_detail.php?id=blog_title

但我希望使用.htaceess更改网址,如下所示:http://domain.com/blog/blog_title

我试过这个,但它不起作用:

<IfModule mod_rewrite.c>
    RewriteEngine on   # Turn on the rewriting engine
    RewriteRule ^blog/([a-zA-Z0-9_-]+)$ blog_detail.php?id=$1
</IfModule>

2 个答案:

答案 0 :(得分:1)

我会用:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f ## respect real files
RewriteCond %{REQUEST_FILENAME} !-d ## respect real directories
RewriteBase /                       

RewriteRule ^blog/(.*)$ blog_detail.php?id=$1&%{QUERY_STRING} [L]

&amp;%{QUERY_STRING}只有在您想要传递其他变量时才会这样:

http://domain.com/blog/blog_title?lang=fr
例如

答案 1 :(得分:0)

试试这个:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /blog/
    RewriteRule ^(.*)$ blog_detail.php?id=$1 [QSA,L]
</IfModule>
相关问题