我将以下网址之一传递给网站,希望将其拆分为正确的参数。
http://example.com/storevar?search_term
http://example.com/storevar/?search_term
http://example.com/storevar
http://example.com/storevar/
http://example.com/storevar/search_term
http://example.com/storevar/search_term/
http://example.com/storevar/search_term/mode
http://example.com/storevar/search_term/mode/
然后他们应该将信息传递给
http://example.com/process.php?store=$1&search=$2&mode=$3
以下.HTACCESS文件信息可以处理前6个项目,但不处理“模式”信息。
Options +FollowSymLinks
RewriteEngine On
# For /storevar?search_term and /storevar/?search_term
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^([^/]+)/?$ /process.php?store=$1&search=%{QUERY_STRING} [L]
# For /storevar/search_term, /storevar/search_term/ and /storevar/
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^([^/]+)(?:/([^/]+))?/?$ /process.php?store=$1&search=$2 [QSA,L]
我的RewriteRule RegEx技能很差,所以我不知道如何处理所有可能的变化。
我如何添加“模式”变体?
答案 0 :(得分:1)
对于这些:
http://example.com/storevar/search_term/mode
http://example.com/storevar/search_term/mode/
使用这个:
RewriteRule ^(?!process\.php)([^/]+)(?:/([^/]+)(?:/([^/]+))?)?/?$ /process.php?store=$1&search=$2&mode=$3 [L]