我试图创建网站,我需要将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]
## 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的事情,但我做了所有我能做到的(我想是的)
答案 0 :(得分:1)
感谢@ hjpotter92,这个问题已经解决了。
我错过了一个问号,这就是为什么这段代码有点破碎了 这是正确的字符串:
^([a-z]{2})/(dashboard)(?:/([^/]+)(?:/([^/]+))?(?:/([^/]+))?)?/?$
所有我错过的是
^([a-z]{2})/(dashboard)(?:/([^/]+)(?:/([^/]+))
? (?:/([^/]+))?)?/?$
这是完全正确的代码
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]