url重写中的参数子域

时间:2014-01-31 11:17:13

标签: php .htaccess mod-rewrite subdomain

我有一个漂亮的网址

例如:www.mydomain.co.in到subdomain.mydomain.co.in,它完美无缺。

我面临的问题是参数.... 我收到了subdomain.mydomain.co.in/category?id=250 ....必须使用.htaccess更改为subdomain.mydomain.co.in/category/250 ..

是的,有很多链接适用于www.mydomain.co.in?id=250到www.mydomain.co.in/250 ..

必须进行哪些更改才能包含子域。输出应该像subdomain.mydomain.co.in/category/250

.htaccess文件如下所示

 RewriteEngine On

 #subdomain and folders
 RewriteCond %{HTTP_HOST} !^subdomain\.mydomain.co.in [NC]

 RewriteRule ^(.*)$ http://subdomain.mydomain.co.in/$1 [R=301,L]

 #remove .php and ad slash
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteRule ^([^/]+)/$ http://mydomain.co.in/subdomain/$1 [R=301,L]

 # Redirect external .php requests to extensionless url
 RewriteCond %{THE_REQUEST} ^(.+)\.php([#?][^\ ]*)?\ HTTP/
 RewriteRule ^(.+)\.php$ http://mydomain.co.in/subdomain/$1 [R=301,L]

 # Resolve .php file for extensionless php urls
 RewriteRule ^([^/.]+)$ $1.php [L]

1 个答案:

答案 0 :(得分:1)

您需要2个新规则来处理category。试试这段代码:

 RewriteEngine On

 #subdomain and folders
 RewriteCond %{HTTP_HOST} !^subdomain\.mydomain.co.in [NC]
 RewriteRule ^(.*)$ http://subdomain.mydomain.co.in/$1 [R=301,L]

 #remove .php and ad slash
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteRule ^([^/]+)/$ http://mydomain.co.in/subdomain/$1 [R=301,L]

 RewriteCond %{THE_REQUEST} \s/+(category)\?id=([^\s&]+) [NC]
 RewriteRule ^ /%1/%2? [R=302,L]

 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteRule ^(category)/([^/.]+)/?$ /$1?id=$2 [L,QSA,NC]

 # Redirect external .php requests to extensionless url
 RewriteCond %{THE_REQUEST} ^(.+)\.php([#?][^\ ]*)?\ HTTP/
 RewriteRule ^(.+)\.php$ http://mydomain.co.in/subdomain/$1 [R=301,L]

 # Resolve .php file for extensionless php urls
 RewriteRule ^([^/.]+)$ $1.php [L]