使用可选参数智能网址是什么? [英] Smart URL with optional parameters?
本文介绍了使用可选参数智能网址是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
目前,我有这在我的.htaccess文件:
RewriteEngine叙述上
的RewriteBase /
的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-l
的RewriteCond%{} REQUEST_FILENAME!-d
重写规则^(\ w +)(/(\ w +))/ $ route.php 1 = $ 1安培;???2 = $ 3 [L]
所以我可以做 myurl.com/foo/bar(/)
或只是 myurl.com/foo(/)
(可选尾随斜线,稳赚不赔)
我不是很熟悉规则前pression,所以我怎么会有这种允许高达约6个参数(myurl.com/one/two/three/four/five/为6个)
?
解决方案
重写规则^(\ w +)(?:/(\ w +))?(?:/(\ w +) ):)(:/(\ w +?))?(/(\ w +?)?(?:/(\ w +)???)/ $ route.php 1 = $ 1和2 2 = $和3 = $ 3及4 = $ 4和5 = $ 5和6 = $ 6 [L]
您可以检查一下 rel="nofollow">
要允许在参数空间中,你可以使用:
重写规则^([\ w \] +)(?:/([\ w \] +))?(?:/([\ w \] +))? (?:/([\ w \] +))?(?:/([\ w \] +))????(?:/([\ w \] +))/ $ route.php 1 = $ 1和2 2 = $和3 = $ 3和4 = $ 4和5 = $ 5和6 = $ 6 [L]
I currently have this in my .htaccess file:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(\w+)(/(\w+))?/?$ route.php?1=$1&2=$3 [L]
So I can do myurl.com/foo/bar(/)
or just myurl.com/foo(/)
(optional trailing slash, can't lose)
I'm not very familiar with regular expression, so how would I have this allow up to around 6 parameters (myurl.com/one/two/three/four/five/six)
?
解决方案
RewriteRule ^(\w+)(?:/(\w+))?(?:/(\w+))?(?:/(\w+))?(?:/(\w+))?(?:/(\w+))?/?$ route.php?1=$1&2=$2&3=$3&4=$4&5=$5&6=$6 [L]
You can check it here
To allow spaces in the parameters you can use:
RewriteRule ^([\w\ ]+)(?:/([\w\ ]+))?(?:/([\w\ ]+))?(?:/([\w\ ]+))?(?:/([\w\ ]+))?(?:/([\w\ ]+))?/?$ route.php?1=$1&2=$2&3=$3&4=$4&5=$5&6=$6 [L]
这篇关于使用可选参数智能网址是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文