开发者

Rewriting different URL from one page to another using .htaccess

I need to know if there is a way to redirect long URLs to short URLs.

I have an RSS page that will list out a number of news items from my website. The URL format of each item (as per MySQL query) is something like http://example.com/news.php?id=2.

On my news.php (after being redirected to the news page upon clicking on any news title on the RSS page), there are parameters set to carry along the IDs which looks like http://example.com/news.php?news=2&view=1&topic=12.

For SEO purpose, I need to erase that dirty query string so that v开发者_开发技巧iewers will only see http://example.com/news.php?id=2 while on the server-side, it actually reads http://example.com/news.php?news=2&view=1&topic=12.

I had created an .htaccess file and it is placed inside the rss folder (where the rss.php file is located ) and tried several attempts but to no available.

Help me on this.


Here's what I would do:

RewriteEngine on

# id + view + topic
# http://www.domain.com/news/1/1/12 will load: /news.php?news=1&view=1&topic=12
RewriteRule ^news/([0-9]+)/([0-9]+)/([0-9]+)(/?)$ /news.php?news=$1&view=$2&topic=$3 [QSA,L,NC]

Please this .htaccess in the root folder.


Should the parameters be assigned to ($1,$2,$3...etc) instead?

 RewriteRule ^news(/?)$ /news.php?news=$1&view=$2&topic=$3 [QSA,L,NC]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜