[英].htaccess URL Rewrite if a parameter is not exist
以下是我用來在.htaccess
文件中進行網址重寫的代碼
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteRule pages/(.*)/? /page/index.php?name=$1 [NC,L]
從上面的代碼中,如果該網址是www.example.com/pages/2
則實際上它會轉到該網址www.example.com/page/index.php?name=2
但我也想要這樣的東西:如果頁面請求是www.example.com/pages/2/user/rahul
那么它也應該轉到相同的網址www.example.com/page/index.php?name=2&user=rahul
所以做上述事情,我做了這樣的事情:
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteRule pages/(.*)/? /page/index.php?name=$1 [NC,L]
RewriteRule pages/(.*)/user/(.*)/? /page/index.php?name=$1&user=$2 [NC,L]
但我不想要它。
嘗試:
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteRule ^pages/([^/]+)/user/([^/]+)/?$ /page/index.php?name=$1&user=$2 [NC,L]
RewriteRule ^pages/([^/]+)/?$ /page/index.php?name=$1 [NC,L]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.