0

I have the following Rewrite Rule

RewriteRule ^/product/([^/]*)/([^/]*)/([^/]*)/([^/]*)/((test_data|data_test)/)?([^/]*)$ /product/?query_one=$1&query_two=$2&query_three=$3&query_four=$4&file_path=$6/$7

In last file_path's value I am combining $6/$7.

Is it possible if $6 has no value then file_path will only be $7? I don't want / id $6 is None. In simple I want to put condition in this part.

Edit

https://example.com/product/one/two/three/four/test_data/file.jar

TO

https://example.com/product/?query_one=one&query_two=two&query_three=three&query_four=four&file_path=test_data/file.jar

Problem is with this URL

https://example.com/product/one/two/three/four/test_file.xml

Please suggest?

Thanks!

4

1 回答 1

0

看起来你只需要稍微简化你的匹配模式。以下对我有用:

RewriteRule ^/?product/([^/]*)/([^/]*)/([^/]*)/([^/]*)/(.*?)/?$ /product/?query_one=$1&query_two=$2&query_three=$3&query_four=$4&file_path=$5 [L,QSA,NC]

或者,如果您想确保 dir 仅(test_data|data_test)使用:

RewriteRule ^/?product/([^/]*)/([^/]*)/([^/]*)/([^/]*)/((?:(?:test_data|data_test)/)?.*?)/?$ /product/?query_one=$1&query_two=$2&query_three=$3&query_four=$4&file_path=$5 [L,QSA,NC]
于 2013-06-26T11:49:21.970 回答