使用可选参数智能网址是什么?可选、参数、网址、智能

2023-09-02 20:34:45 作者:长相依

目前,我有这在我的.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]
 

您可以检查一下

振动在线监测系统概述及功能特点

要允许在参数空间中,你可以使用:

 重写规则^([ 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]

 
精彩推荐
图片推荐