簡體   English   中英

htaccess-無需重定向的seo友好網址

[英]htaccess - seo friendly url without redirect

我有一個包含以下頁面的網站:

http://www.mywebsite.com/our-services

哪些也可以具有url參數來更改顯示的內容

http://www.mywebsite.com/our-services?grade=1093              // 1093 = medium)
http://www.mywebsite.com/our-services?grade=2890              // 2890 = high)
http://www.mywebsite.com/our-services?grade=2890&p=2          // p = page

我現在希望能夠將它們作為seo友好/整潔的網址,但沒有301重定向。 理想情況下,我想將上述網址作為示例:

http://www.mywebsite.com/our-services/medium-services
http://www.mywebsite.com/our-services/high-services
http://www.mywebsite.com/our-services/high-services/page-2

可以使用htaccess嗎? 我是否認為使用htaccess進行內部重定向可以實現此目的而無需用戶重定向? 看這里,我發現這篇文章是相同的,但略有不同。 另外,當我嘗試該示例即:

RewriteEngine On

RewriteCond %{THE_REQUEST} ^GET\ /ucp/profile\.php?([^=]+)=(\S+) [NC]
RewriteRule ^ucp/profile\.php$ /ucp/%1/%2? [R=301,L,NC]

# Now, deal with internal rewrites (which will not cause redirection):
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ucp/([^/]+)/([^/]+)/?$ /ucp/profile.php?$1=$2 [NC,L]

當我在虛擬頁面中對其進行測試時,我轉到:

mysite.com/ucp/profile.php?player=Heartfire

它給了我以下頁面:

mysite.com/ucp/?player/Heartfire%3f

它應該是:

mysite.com/ucp/profile/heartfire

您的第一個RewriteCond需要調整以逃脫?

RewriteEngine On

RewriteCond %{THE_REQUEST} ^GET\ /ucp/profile\.php\?([^=]+)=(\S+) [NC]
RewriteRule ^ /ucp/%1/%2? [R=301,L,NC,NE]

# Now, deal with internal rewrites (which will not cause redirection):
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ucp/([^/]+)/([^/]+)/?$ ucp/profile.php?$1=$2 [NC,L,QSA]

# new rules for /our-services/...
RewriteRule ^(our-services)/high-\w+/?$ $1?grade=2890 [L,NC,QSA]
RewriteRule ^(our-services)/high-\w+/page-(\d+)/?$ $1?grade=2890&p=$2 [L,NC,QSA]

RewriteRule ^(our-services)/medium-\w+/?$ $1?grade=1093 [L,NC,QSA]
RewriteRule ^(our-services)/medium-\w+/page-(\d+)/?$ $1?grade=1093&p=$2 [L,NC,QSA]

暫無
暫無

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

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