我有一个RewriteCond来设置环境变量中的当前工作目录,如下所示:
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]
对于REQUEST_URI:
/es/website-design/do-it-yourself-website-builder.php
CWD设置为值'/ es /'
但是对于REQUEST_URI:
/de/website-design/do-it-yourself-website-builder.php
CWD设置为值'/ de / website-design /'
理想情况下,CWD应在上述情况下存储基本文件夹名称(分别为'/ es /'和'/ de /')。
这里出了什么问题?我现在已经坚持了很长一段时间。
请帮忙。
.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]
答案 0 :(得分:0)
确保每个规则都有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直接放在站点根目录中。