1

I'm currently working on a blog portal, and I'm trying to achieve a specific thing here.

This is my .htaccess code:

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.[NC]
RewriteCond %{HTTP_HOST} ^(.+?)\.MyDomain.com$ [NC]
RewriteRule ^$ blogdisplay.php?page=%1 [L,QSA]
RewriteRule ^([a-zA-Z0-9-]+)$ index.php?page=$1
RewriteRule ^([a-zA-Z0-9-]+)/$ index.php?page=$1
RewriteRule ^([a-zA-Z0-9-]+)/([a-zA-Z0-9-]+)$ index.php?page=$1&page2=$2
RewriteRule ^([a-zA-Z0-9-]+)/([a-zA-Z0-9-]+)/$ index.php?page=$1&page2=$2
RewriteRule ^([a-zA-Z0-9-]+)/([a-zA-Z0-9-]+)/([a-zA-Z0-9-]+)$ index.php?    page=$1&page2=$2&page3=$3
RewriteRule ^([a-zA-Z0-9-]+)/([a-zA-Z0-9-]+)/([a-zA-Z0-9-]+)/$ index.php?page=$1&page2=$2&page3=$3

When a person is trying to reach SOMETHING.mydomain.com, htaccess is rewriting it to blogdisplay.php?page=BLOGNAME. Just as planned. Now, the problem is that I want it to behave exactly like the main website and rewrite SOMETHING.mydomain.com/page to blogdisplay.php?page=BLOGNAME?page2=page.

Is there any way to make the subdomain use blogdisplay.php instead of index.php, but otherwise work exactly like the subpages of the "main website"?

4

1 回答 1

0

用这个替换你的代码:

RewriteEngine On

RewriteCond %{HTTP_HOST} !^www.[NC]
RewriteCond %{HTTP_HOST} ^(.+?)\.MyDomain.com$ [NC]
RewriteRule ^$ blogdisplay.php?page=%1 [L,QSA]

## If the request is for a valid file
RewriteCond %{REQUEST_FILENAME} -f
## don't do anything
RewriteRule ^ - [L]

RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^(.+?)\.MyDomain\.com$ [NC]
RewriteRule ^([a-z0-9-]+)/?$ blogdisplay.php?page=%1&page2=$1 [L,QSA]

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]
于 2013-09-21T16:39:07.697 回答