English 中文(简体)
选择 2. 单凭这种取用
原标题:Make an optional Get variable with this htaccess
  • 时间:2011-11-22 16:40:46
  •  标签:
  • .htaccess

I have this rule in my .htaccess:

RewriteRule ^build_system/([^/]+)/([^/]+)/([^/]+)/?$ /po_systems/build_system.php?business_id=$1&system_id=$2&quantity=$3

这对这个时代大有好处:

http://somesite.com/po_systems/build_system/60/495C31/1

但现在,我需要任择的第四版<代码>。 本条细则的变量:_$_GET

http://somesite.com/po_systems/build_system/60/495C31/1/2

$_GET[ step ] // 2

But I also need the rule to work if there is no 4th Get variable. So basically I need both 3 and 4 Get variables to work, making the 4th optional.

最佳回答

我将用两项单独的规则写成:

RewriteRule ^build_system/([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$ /po_systems/build_system.php?business_id=$1&system_id=$2&quantity=$3&step=$4 [S=1]
RewriteRule ^build_system/([^/]+)/([^/]+)/([^/]+)/?$         /po_systems/build_system.php?business_id=$1&system_id=$2&quantity=$3

如果有4个路径组成部分,则第1条将相应适用,并绕过下一个规则([S=1])。 否则,下一条规则将试图做到一致。

@Ulrich Palha的解决办法可能也奏效,但经常表达方式正在变得复杂。 如果第4条道路部分没有的话,它将通过空洞的<条码>步骤=参数。 如果不存在第4条道路构成部分,那么我的解决办法将不会通过<条码>分步骤参数。 这两种方式都应奏效。

问题回答

审判

RewriteRule ^build_system/([^/]+)/([^/]+)/([^/]+)/?([^/]*)/?$ /po_systems/build_system.php?business_id=$1&system_id=$2&quantity=$3&step=$4




相关问题
Ignore symlinks in clean URL s in .htaccess

Example URL: example.com/user /user is both a symlinked directory and a valid URL to content on my site. I user Horde Routes to request the content and all requests to the site go through index.php. ...

.htaccess File Options -Indexes on Subdirectories

I have the following .htaccess line, simple no indexes on root. Options -Indexes What do we add so it propagates to any sub directory instead of having to create one file for each? One .htaccess on ...

Mod Rewrite ignoring -d

After a day or two, I am still fighting with Mod Rewrite. It seems that 60% of my development time is spent battling the server. My current URL structure is such that all http://example.com/xyz and ...

ErrorDocument 404 Not Sending Referrer Information: PHP

I m using a standard htaccess ErrorDocument 404 to redirect users to a new page. In order to customize the 404, I need to know their referrer information (from the page they Tried to visit). $...

Find all htaccess files on server [closed]

I m looking for a Linux command to go through all the directories on my server and find all .htaccess files. The output would be a list of all those files with full path, creation/modification date ...

301 Redirect Help with Dynamic URL s and Multiple Id s

I just did a redesign for www.wildchildclothes.com which has a new URL structure. The old site ran on Zen Cart and had a bad URL structure. Here are some examples of what I want to redirect from: OLD:...

热门标签