簡體   English   中英

如何使URL用戶友好?

[英]How to make a URL user friendly?

我的網站上有一些頁面沒有用戶友好的URL。 例如

www.mysite.com/index.php?route=product/category&path=68&vendorId=Cookie%20Dough

因此,我想使用.htaccess將其直接更改為www.mysite.com/Cookie-Dough 到目前為止,我已經在.htaccess中對以下代碼進行了硬編碼。

RewriteRule ^Cookie-Dough index.php?route=product/category&path=68&vendorId=Cookie%20Dough [NC,L]

工作正常。 但是問題是我的供應商ID可以更改,所以我希望它是動態的。 假設我有另一個網址,例如

www.mysite.com/index.php?route=product/category&path=68&vendorId=JELLY%20BEANZ比我希望它成為www.mysite.com/JELLY-BEANZ而不用硬編碼.htaccess中的代碼。

任何幫助,將不勝感激。

/store替換為您自己的子目錄:

---.htaccess file start ----

Options +FollowSymlinks

RewriteEngine On
RewriteBase /store
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\?*$ index.php?_route_=$1 [L,QSA]

# Added for non www queries
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule (.*) http://www .%{HTTP_HOST}/store/$1 [R=301,L]
---.htaccess file ends ----

您可以使用以下規則:

RewriteRule ^([^-]+)-([^/]+)/?$ index.php?route=product/category&path=68&vendorId=$1%20$2 [NC,L]

這將重寫

/foo-bar

/ index.php?route=product/category&path=68&vendorId=foo%20bar 

暫無
暫無

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

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