我正在尝试在我的博客门户上使用 htaccess 实现以下目标:
结构 1
example.domain.com/link/sublink -> /blogdisplay.php?page=example&page2=link&page3=sublink
结构 2
en.domain.com/link/sublink/subsublink -> /index.php?lang=en&page=link&page2=sublink&page3=subsublink
结构 3
domain.com/link/sublink/subsublink -> /index.php?page=link&page2=sublink&page3=subsublink
我如何实现这一目标?这是我当前的代码(它现在根本不处理语言,但其他两个 URL 结构工作正常):
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.domain.com [NC]
RewriteRule ^(.*)$ http://domain.com/$1 [L,R=301]
RewriteCond %{HTTP_HOST} !^www.[NC]
RewriteCond %{HTTP_HOST} ^([a-zA-Z0-9-]{3,})\.domain.com$ [NC]
RewriteRule ^$ blogdisplay.php?page=%1 [L,QSA]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^(.+?)\.domain\.com$ [NC]
RewriteRule ^([a-z0-9-]+)/?$ blogdisplay.php?page=%1&page2=$1 [L,QSA]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^(.+?)\.domain\.com$ [NC]
RewriteRule ^([a-z0-9-]+)/([a-zA-Z0-9-]+)/?$ blogdisplay.php?page=%1&page2=$1&page3=$2 [L,QSA]
## If the request is for a valid file
RewriteCond %{REQUEST_FILENAME} -f
## don't do anything
RewriteRule ^ - [L]
RewriteRule ^([a-z0-9-]+)/?$ index.php?page=$1 [L,NC]
RewriteRule ^([a-z0-9-]+)/([a-zA-Z0-9-]+)/?$ index.php?page=$1&page2=$2 [L,NC]
RewriteRule ^([a-z0-9-]+)/([a-zA-Z0-9-]+)/([a-zA-Z0-9-]+)/?$ index.php?page=$1&page2=$2&page3=$3 [L,NC]