簡體   English   中英

.htaccess-使用鏈編寫高效代碼,下一個用於URL重定向

[英].htaccess - writing efficient codes using chain, next for url redirects

假設我在用戶瀏覽頁面(www.date.com)上具有以下URL:www.date.com/Location-A/Education-B/Sex-C/Interest-D/

情況是,用戶只能瀏覽所有(4)個可用條件中的一個(1個或2個)www.date.com/Education-B/或www.date.com/Sex-C/Interest-E/

還要假設URL中瀏覽條件的順序很重要(即A / B-可以,但是B / A不能)

我的.htaccess文件中有代碼

RewriteEngine開

1種可變情況

RewriteRule ^/Location-([^/]+)/$ /index.php?Location=$1 [L]

RewriteRule ^/Education-([^/]+)/$ /index.php?Education=$1 [L]

(......)

2變量情況

(......)

4變量情況

RewriteRule ^/Location-([^/]+)/Education-([^/]+)/Sex-([^/]+)/Interest-([^/]+)/$ /index.php?Location=$1&Education=$2&Sex=$3&Interest=$4 [L]

如果我有8個變量,這將變得很愚蠢。

有沒有實現上述目標的更明智的方法? 可能使用[C]-鏈條或[N]-下一個? (URL變量的順序很重要)

提前致謝

嘗試這個:

RewriteRule ^/([^-]+)-([^/]+)/$ /index.php?$1=$2 [L]
RewriteRule ^/([^-]+)-([^/]+)/([^-]+)-([^/]+)/$ /index.php?$1=$2&$3=$4 [L]
RewriteRule ^/([^-]+)-([^/]+)/([^-]+)-([^/]+)/([^-]+)-([^/]+)/$ /index.php?$1=$2&$3=$4&$5=$6 [L]
RewriteRule ^/([^-]+)-([^/]+)/([^-]+)-([^/]+)/([^-]+)-([^/]+)/([^-]+)-([^/]+)/$ /index.php?$1=$2&$3=$4&$5=$6&$7=$8 [L]
...

暫無
暫無

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

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