Regex 他贪婪地匹配

Regex 他贪婪地匹配,regex,mod-rewrite,url-rewriting,regex-greedy,Regex,Mod Rewrite,Url Rewriting,Regex Greedy,我有一个重写条件,可以在环境变量中设置当前工作目录,如下所示: RewriteCond $0#%{REQUEST_URI} ([^#]*)#(.*?/)\1$ RewriteRule ^(.*)$ - [E=CWD:%2] 在这两条规则之上,我有一条单独的重写规则 RewriteRule ^(?!ui?)([a-zA-Z]{2})/(.*)$ $2?language=$1 [NC,QSA] 总的来说,我的.htaccess部分看起来像: RewriteRule ^(?!ui?)([a-zA

我有一个重写条件,可以在环境变量中设置当前工作目录,如下所示:

RewriteCond $0#%{REQUEST_URI} ([^#]*)#(.*?/)\1$
RewriteRule ^(.*)$ - [E=CWD:%2]
在这两条规则之上,我有一条单独的重写规则

RewriteRule ^(?!ui?)([a-zA-Z]{2})/(.*)$  $2?language=$1 [NC,QSA]
总的来说,我的.htaccess部分看起来像:

RewriteRule ^(?!ui?)([a-zA-Z]{2})/(.*)$  $2?language=$1 [NC,QSA]

RewriteCond $0#%{REQUEST_URI} ([^#]*)#(.*?/)\1$
RewriteRule ^(.*)$ - [E=CWD:%2]
对于请求URI:

/es/website-design/do-it-yourself-website-builder.php
/de/website-design/do-it-yourself-website-builder.php
CWD被设置为值'/es/'

但是对于请求_URI:

/es/website-design/do-it-yourself-website-builder.php
/de/website-design/do-it-yourself-website-builder.php
CWD被设置为值“/de/website design/”

理想情况下,CWD应在上述情况下存储基本文件夹名('/es/'和'/de/')

这里出了什么问题?我被这件事困扰了很长一段时间

请帮忙

my.htaccess文件的内容:

RewriteEngine On
RewriteBase /

RewriteCond $2 !^(index\.php)
RewriteRule ^(shop)/(.*)$  $2 [NC,QSA]

RewriteCond %{THE_REQUEST} ^.*/(shop)/index\.php
RewriteRule ^(.*)index.php$ /$1 [R=301,QSA,L]

RewriteRule ^(?!ui?)([a-zA-Z]{2})/(.*)$  $2?language=$1 [NC,QSA]

# following tweak done for running supersite from within a folder
# for ever request url , this rule will match out the base folder
# name and capture it in the regex rule given in RewriteCond
RewriteCond $0#%{REQUEST_URI} ([^#]*)#(.*?/)\1$
RewriteRule ^(.*)$ - [E=CWD:%2]

# Preventing Hot Linking of images
#RewriteCond %{REQUEST_URI} ^\/getImage\.php [NC]
#RewriteCond %{HTTP_REFERER} !^.*(manage.bigrock.in|manage.bigrock.com).*$ [NC]
#RewriteCond %{REQUEST_URI} .*\.css$ [NC,OR]
#RewriteCond %{REQUEST_URI} .*\.js$ [NC,OR]
#RewriteCond %{QUERY_STRING} !^src\=favicon\.ico$ [NC]
#RewriteCond %{HTTP_REFERER} ^http://([^/]+) [OR]
#RewriteCond %{HTTP_REFERER} ^$
#RewriteCond %{HTTP_HOST}<>%1 !^(.+)<>\1$ [NC]
#RewriteRule ^(.*)$ /noimage.html [Last]

RewriteCond %{HTTP_USER_AGENT} ^GlobalSign-Approver
RewriteRule ^(.*)$ cloudflare.html [L]

RewriteCond %{SERVER_PORT} 80
RewriteRule ^/onlinepayment/(.*)$  https://%{HTTP_HOST}/onlinepayment/$1  [NC,QSA]

RewriteCond %{REQUEST_METHOD} !POST
RewriteRule ^index\.php$ / [R=301,QSA,L]

RewriteCond %{REQUEST_FILENAME} (S|s)itemap.xml
RewriteRule ^(.*)$  /seo-files.php?type=sitemap  [L]

RewriteCond %{REQUEST_FILENAME} ror.xml
RewriteRule ^(.*)$  /seo-files.php?type=ror [L]

RewriteCond %{REQUEST_FILENAME} urllist.txt
RewriteRule ^(.*)$  /seo-files.php?type=urllist [L]

# Robots.txt redirection to robots.php
RewriteRule ^robots.txt robots.php [L,NC]

# URL rewriting
RewriteRule ^domain-registration-pricing$ /domain-registration/domain-registration-price.php [R=302,L,NC,QSA]
RewriteRule ^domain-registration/transfer/index.php /domain.php?action=domain_transfer&bypass_url_mapper=false [L,NC,QSA]

RewriteCond %{QUERY_STRING} ^idn
RewriteRule .*domain-registration/index.php /domain-registration/idn? [R=301,L]

RewriteRule ^promos.php /content.php?action=promos [L,NC,QSA]

RewriteRule ^website-design/index.php /sitebuilder.php?type=sblite&bypass_url_mapper=false [L,NC,QSA]
#RewriteRule ^website-design/do-it-yourself-website-builder.php  %{ENV:CWD}website-design/index.php? [R=301,L,NC]
RewriteRule ^website-design/web-design-service.php /website-design/index.php [R=301,L,NC,QSA]
RewriteRule ^website-design/(.*).js$ /$1.js [L,NC,QSA]

RewriteRule ^website-builder.php$ /website-design/index.php [R=301,L,NC,QSA]
RewriteRule ^do-it-yourself.php$ /website-design/index.php [R=301,L,NC,QSA]
RewriteRule ^build-it-for-me.php$ /website-design/index.php [R=301,L,NC,QSA]

RewriteRule ^combo-offers /product-bundle.php [L,NC,QSA]

RewriteRule ^express-cart[/]{0,1}([a-zA-Z0-9_]*)[/]{0,1}$ /quickbuy.php?action=$1 [L,NC,QSA]
RewriteRule ^express-cart[/]{0,1}([a-zA-Z0-9_]*)[/]{1}([a-zA-Z0-9_]*)[/]{0,1}$ /quickbuy.php?action=$1_$2 [L,NC,QSA]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /urlmapper.php [L,QSA]
重新编写引擎打开
重写基/
2美元^(index\.php)
重写规则^(车间)/(.*)$$2[NC,QSA]
重写cond%{THE_REQUEST}^.*/(shop)/index\.php
重写规则^(.*)index.php$/$1[R=301,QSA,L]
重写规则^(?!ui?([a-zA-Z]{2})/(.*)$$2?语言=$1[NC,QSA]
#为从文件夹中运行supersite,完成了以下调整
#对于永久请求url,此规则将匹配基本文件夹
#命名并在RewriteCond中给出的正则表达式规则中捕获它
重写第二个$0#%{REQUEST#u URI}([^#]*)#(.*?/)\1$
重写规则^(.*)-[E=CWD:%2]
#防止图像热链接
#重写cond%{REQUEST_URI}^\/getImage\.php[NC]
#重写cond%{HTTP_REFERER}!^*(manage.bigrock.in | manage.bigrock.com)。*$[NC]
#RewriteCond%{REQUEST_URI}.*\.css$[NC,或]
#RewriteCond%{REQUEST_URI}.*\.js$[NC,或]
#重写cond%{QUERY_STRING}^src\=favicon\.ico$[NC]
#重写cond%{HTTP_REFERER}^HTTP://([^/]+)[或]
#重写cond%{HTTP_REFERER}^$
#重写cond%{HTTP_HOST}%1^(.+)\1$[NC]
#重写规则^(.*)$/noimage.html[上次]
RewriteCond%{HTTP\u USER\u AGENT}^GlobalSign审批人
重写规则^(.*)$cloudflare.html[L]
重写cond%{SERVER_PORT}80
重写规则^/onlinepayment/(.*)$https://%{HTTP_HOST}/onlinepayment/$1[NC,QSA]
重写cond%{REQUEST_METHOD}!邮递
重写规则^index\.php$/[R=301,QSA,L]
重写cond%{REQUEST_FILENAME}(S|S)itemap.xml
重写规则^(.*)$/seo files.php?type=sitemap[L]
RewriteCond%{REQUEST_FILENAME}ror.xml
重写规则^(.*)$/seo files.php?type=ror[L]
RewriteCond%{REQUEST_FILENAME}urlist.txt
重写规则^(.*)$/seo files.php?type=urlist[L]
#Robots.txt重定向到Robots.php
重写规则^robots.txt robots.php[L,NC]
#URL重写
重写规则^domain registration pricing$/domain registration/domain-registration-price.php[R=302,L,NC,QSA]
重写规则^domain registration/transfer/index.php/domain.php?action=domain\u transfer&pass\u url\u mapper=false[L,NC,QSA]
重写条件%{QUERY\u STRING}^idn
重写规则。*域注册/index.php/domain注册/idn?[R=301,L]
重写规则^promos.php/content.php?action=promos[L,NC,QSA]
重写规则^website design/index.php/sitebuilder.php?type=sblite&bypass\u url\u mapper=false[L,NC,QSA]
#重写规则^website design/do-it-yourself-website-builder.php%{ENV:CWD}website design/index.php?[R=301,L,NC]
重写规则^website design/web-design-service.php/website design/index.php[R=301,L,NC,QSA]
重写规则^website design/(.*).js$/$1.js[L,NC,QSA]
重写规则^website builder.php$/website design/index.php[R=301,L,NC,QSA]
重写规则^do it yourself.php$/website design/index.php[R=301,L,NC,QSA]
重写规则^build it for me.php$/website design/index.php[R=301,L,NC,QSA]
重写规则^combo offers/product-bundle.php[L,NC,QSA]
重写规则^express cart[/]{0,1}([a-zA-Z0-9\]*)[/]{0,1}$/quickbuy.php?操作=$1[L,NC,QSA]
重写规则^express cart[/]{0,1}([a-zA-Z0-9\]*)[/]{1}([a-zA-Z0-9\]*)[/]{0,1}$/quickbuy.php?操作=$1\$2[L,NC,QSA]
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则^(.*)$/urlmapper.php[L,QSA]

确保每个规则都有
L
标志,例如

RewriteRule ^(?!ui?)([a-zA-Z]{2})/(.*)$  $2?language=$1 [NC,QSA]
应该是

RewriteRule ^(?!ui?)([a-zA-Z]{2})/(.*)$  $2?language=$1 [NC,L,QSA]
然后完全清除浏览器缓存


Env变量
CWD
应始终作为
/
出现,因为htaccess直接放置在站点根目录中。

确保每个规则都有
L
标志,例如

RewriteRule ^(?!ui?)([a-zA-Z]{2})/(.*)$  $2?language=$1 [NC,QSA]
应该是

RewriteRule ^(?!ui?)([a-zA-Z]{2})/(.*)$  $2?language=$1 [NC,L,QSA]
然后完全清除浏览器缓存


Env变量
CWD
应始终以
/
的形式出现,因为htaccess直接放在站点根目录中。

CWD应分别返回基本文件夹名('/es/'和'/de/')。在我的根文件夹中,在'es'和'de'文件夹之外,这就是问题所在。您展示的规则是计算我们的
RewriteBase
路径。这意味着从站点根的相对路径。如果.htaccess本身在站点根目录中,那么
RewriteBase
就是
/
确保每个规则都有
L
标志,例如
RewriteRule^(?ui?)([a-zA-Z]{2})/(.*)$$2?语言=$1[NC,QSA]
应该是
RewriteRule^(?ui?([a-zA-Z]{2})/(.$2?语言=$1[NC,L,QSA]
然后完全清除浏览器缓存
CWD
总是像
/
一样为我而来。谢谢@anubhava。已排序的问题。CWD应分别返回基本文件夹名('/es/'和'/de/')。在我的根文件夹中,在'es'和'de'文件夹之外,这就是问题所在。您展示的规则是计算我们的
RewriteBase
路径。这意味着从站点根的相对路径。如果.htaccess本身在站点根目录中,那么
RewriteBase
就是
/
确保每个规则都有
L
标志,例如
RewriteRule^(?ui?)([a-zA-Z]{2})/(.*)$$2?语言=$1[NC,QSA]
应该是
RewriteRule^(?ui?([a-zA-Z]{2})/(.$2?语言=$1[NC,L,QSA]
然后完全清除浏览器缓存
CWD
总是像
/
一样为我而来。谢谢@anubhava。这就解决了问题。