Apache htaccess重写虚拟文件夹
我试图创建网站,我需要重写php文件切换案例到虚拟目录 我正在尝试创建类型为Apache htaccess重写虚拟文件夹,apache,.htaccess,mod-rewrite,Apache,.htaccess,Mod Rewrite,我试图创建网站,我需要重写php文件切换案例到虚拟目录 我正在尝试创建类型为http://localhost/en/dashboard/mailbox/send/username 要工作,请使用以下代码 RewriteEngine On RewriteCond %{REQUEST_URI} ^(.*)//(.*)$ RewriteRule . %1/%2 [R=301,L] RewriteCond %{HTTP:Accept-Language} ^([a-z]{2})- [NC] ## Rew
http://localhost/en/dashboard/mailbox/send/username
要工作,请使用以下代码
RewriteEngine On
RewriteCond %{REQUEST_URI} ^(.*)//(.*)$
RewriteRule . %1/%2 [R=301,L]
RewriteCond %{HTTP:Accept-Language} ^([a-z]{2})- [NC]
## Rewrite Rules
RewriteRule ^/?$ /%1/%{REQUEST_URI} [L,NC,R]
RewriteRule ^([a-z]{2})/?$ /index.php?language=$1 [L,NC,QSA]
RewriteRule ^account/?$ /%1%{REQUEST_URI} [L,NC,R]
RewriteRule ^([a-z]{2})/(account)(?:/([^/]+)(?:/([^/]+))?)?/?$ account.php?language=$1&action=$3 [L,NC]
RewriteRule ^dashboard/?$ /%1%{REQUEST_URI} [L,NC,R]
RewriteRule ^([a-z]{2})/(dashboard)(?:/([^/]+)(?:/([^/]+))(?:/([^/]+))?)?/?$ /$2.php?language=$1&type=$3&subtype=$4&lasttype=$5 [L,NC,QSA]
但是,从现在起,我无法访问http://localhost/en/dashboard/mailbox/
本身
有人能帮我解决这个问题吗?我对htaccess一点也不感兴趣,但到目前为止我已经尽了我所能(我想是的)多亏了@hjpotter92,这个问题才得以解决 我漏掉了一个问号,所以这就是为什么这段代码被破坏的原因。
以下是正确的字符串:
^([a-z]{2})/(dashboard)(?:/([^/]+)(?:/([^/]+))?(?:/([^/]+))?)?/?$
我错过的只是^([a-z]{2})/(仪表板)(?:/([^/]+)(?:/([^/]+)
?(?:/([^/]+))?/?$
这是完全正确的代码
RewriteEngine On
RewriteCond %{REQUEST_URI} ^(.*)//(.*)$
RewriteRule . %1/%2 [R=301,L]
RewriteCond %{HTTP:Accept-Language} ^([a-z]{2})- [NC]
## Rewrite Rules
RewriteRule ^/?$ /%1/%{REQUEST_URI} [L,NC,R]
RewriteRule ^([a-z]{2})/?$ /index.php?language=$1 [L,NC,QSA]
RewriteRule ^account/?$ /%1%{REQUEST_URI} [L,NC,R]
RewriteRule ^([a-z]{2})/(account)(?:/([^/]+)(?:/([^/]+))?)?/?$ account.php?language=$1&action=$3 [L,NC]
RewriteRule ^dashboard/?$ /%1%{REQUEST_URI} [L,NC,R]
RewriteRule ^([a-z]{2})/(dashboard)(?:/([^/]+)(?:/([^/]+))?(?:/([^/]+))?)?/?$ /$2.php?language=$1&type=$3&subtype=$4&lasttype=$5 [L,NC,QSA]
在
RewriteRule^dashboard/?$/%1%{REQUEST_URI}[L,NC,R]
中,%1
来自哪里?它是通过解析%{HTTP:Accept language}
获得的语言变量不,它不会。RewriteCond
受以下规则约束。它不适用于以下所有规则。如果我将其设置为(?:/([^/]+)(?:/([^/]+)(?:/([^/]+)(?:/([^/]+)(?:/([^/]+))(?:/([^/]+),
我可以访问邮箱,但不是http://localhost/en/dashboard/mailbox/send/username
P.S.我仍然可以访问send
过程重试此模式:^([a-z]{2})/(仪表板)(?:/([^/]+)(?:/([^/]+)?(?:/([^/]+))(?:/([^/]+)?)?/?$
我认为如果@hjpotter92将此作为答案发布,这样你就可以通过接受它来给他荣誉。@anubhava啊,这个问题只是OP部分缺少的一个?
。我宁愿把它看作是修正了一个打字错误;)\@伊万:你可以选择这篇文章作为答案。