HTACCESS:更改网址更友好

时间:2014-09-29 21:01:15

标签: .htaccess url-rewriting

我希望谷歌的网址更友好,更容易找到谷歌。

这是我的网址: www.myweb.com/news.php?id=12&title=title-of-my-news

我想改为: www.myweb.com/news/12/title-of-my-news

任何人都可以帮助我,htacces上的sysntax?

1 个答案:

答案 0 :(得分:0)

将这些规则添加到文档根目录中的htaccess文件中:

Options -Multiviews
RewriteEngine On

RewriteCond %{THE_REQUEST} \ /+news\.php\?id=([0-9]+)&title=([^&]+)
RewriteRule ^ /news/%1/%2? [L,R]

RewriteCond %{REQUEST_FILENAME) !-f
RewriteCond %{REQUEST_FILENAME) !-d
RewriteRule ^news/([^/]+)/([^/]+)$ /news.php?id=$1&title=$2 [L]

您还需要确保网页上的所有链接都是绝对网址,或者将其添加到您的网页标题中:

<base href="/" />