htaccess将旧网址重写为新的seo网址

时间:2019-07-08 11:32:17

标签: php .htaccess

我今天有一些这样的网址:

http://www.mydomain/nyhet?nid=235-url-name.html

我希望htaccess以这种方式转换为seo URL:

http://www.mydomain/nyhet/235-url-name.html

这是我今天在htaccess中的代码:

 RewriteEngine on
 RewriteBase /

 RewriteCond %{HTTP_HOST} ^mydomain.se [NC]

 RewriteRule ^(.*)$ http://www.mydomain.se/$1 [L,R=301]
 RewriteRule ^([a-zA-Z0-9_-]+)/?$ /index.php?sida=$1 [L,QSA]
 RewriteRule ^nyhet/([a-zA-Z0-9_-]+)(.*)\.html$ /index.php?nyhet=$1

今天/nyhet/124-seo.html在我的系统中运行正常。但是带有/nyhet?nid=124-seo.html的旧网址不会重定向到/nyhet/124-seo.html

我尝试添加:

RewriteEngine on
RewriteBase /

RewriteCond %{HTTP_HOST} ^mydomain.se [NC]

RewriteRule ^(.*)$ http://www.mydomain.se/$1 [L,R=301]

RewriteRule ^(.*)ä(.*)$ /$1a$2 [L,R=301]
RewriteRule ^(.*)å(.*)$ /$1a$2 [L,R=301]
RewriteRule ^(.*)ö(.*)$ /$1o$2 [L,R=301]
RewriteRule ^(.*)Ä(.*)$ /$1A$2 [L,R=301]
RewriteRule ^(.*)Å(.*)$ /$1A$2 [L,R=301]
RewriteRule ^(.*)Ö(.*)$ /$1O$2 [L,R=301]

RewriteCond %{QUERY_STRING} nid=(.*?)($|&) [NC] 
RewriteRule ^/?nyhet /nyhet/%1? [L,R=301]


RewriteRule ^([a-zA-Z0-9_-]+)/?$ /index.php?sida=$1 [L,QSA]
RewriteRule ^nyhet/([a-zA-Z0-9_-]+)(.*)\.html$ /index.php?nyhet=$1

但是服务器错误显示:www.mydomain.se redirected you too many times

有什么主意吗?

0 个答案:

没有答案