重写动态网址

时间:2012-05-20 16:15:30

标签: .htaccess

我有以下问题:

http://www.mydomain.com/articles.php?artid=89

应该成为:http://www.mydomain.com/mykeyword

我不介意ID是否保留在网址中......例如:http://www.mydomain.com/89/mykeyword

我现在有以下.htaccess:

RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} ^(mydomain\.com)$ [NC]
RewriteRule ^(.*)$ http://www.%1/$1 [R=301,L] 

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+news\.php [NC]
RewriteRule ^ mykeyword [R=301,L]

RewriteRule ^mykeyword/?$ news.php [L,NC]

上面的部分就像一个魅力。

任何帮助都将深受赞赏。

关心,佐兰

1 个答案:

答案 0 :(得分:0)

将这些规则附加到.htaccess的底部:

RewriteEngine On
RewriteBase /turkexpo/

RewriteCond %{HTTP_HOST} ^(webone\.gr)$ [NC]
RewriteRule ^(.*)$ http://www.%1/turkexpo/$1 [R=302,L] 

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+turkexpo/news\.php [NC]
RewriteRule ^ mykeyword [R=302,L]

RewriteRule ^mykeyword/?$ news.php [L,NC]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+turkexpo/articles\.php\?artid=([0-9]+) [NC]
RewriteRule ^ %1/mykeyword? [R=302,L]

RewriteRule ^([0-9]+)/mykeyword/?$ articles.php?artid=$1 [L,NC,QSA]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+turkexpo/companies\.php\?fairid=([0-9]+)&ehallid=([0-9]+) [NC]
RewriteRule ^ companies/%1/%2? [R=302,L]

RewriteRule ^companies/([0-9]+)/([0-9]+)/?$  companies.php?fairid=$1&ehallid=$2 [L,NC,QSA]

这会将/89/mykeyword的URI转发给/articles.php?artid=89,并在其外部重定向。

一旦确定它正在运行,请将R=302更改为R=301