簡體   English   中英

htaccess seo友好的URL

[英]htaccess seo-friendly URL's

我需要一些幫助才能在我的網站上獲得友好的URL。

這些是我需要重寫的鏈接:

www.example.com/index.php?page=pagename
www.example.com/index.php?page=profile&id=number

這是我的.htaccess。 我為第一個鏈接解決了該問題,但是對於第二個鏈接卻無法解決。

我想要第二個鏈接:

www.example.com/profile/name or
www.example.com/profile/id

這是我的.htaccess文件:

# for www.example.com/index.php?page=profile&id=number
RewriteCond %{THE_REQUEST} \?page=([^&]+)&id=([0-9]+)
RewriteRule ^ /%1/%2? [L,R=301]

# for www.example.com/index.php?page=page
RewriteCond %{THE_REQUEST} \?page=([^&\ ]+)($|\ )
RewriteRule ^ /%1? [L,R=301]

# rewrites back
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/([0-9]+)$ /index.php?page=$1&id=$2 [L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)$ /index.php?page=$1 [L]

我上面提交的代碼解決了我的問題。

您可以使用:

# for www.example.com/index.php?page=profile&id=number
RewriteCond %{QUERY_STRING} page=([^&]+)&id=([0-9]+)
RewriteRule ^ /%1/%2? [L,R=301]

# for www.example.com/index.php?page=page
RewriteCond %{QUERY_STRING} page=([^&]+)
RewriteRule ^ /%1? [L,R=301]

並重寫

# rewrites back
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]

RewriteRule ^([^/]+)/([0-9]+)$ /index.php?page=$1&id=$2 [L]
RewriteRule ^([^/]+)$ /index.php?page=$1 [L]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM