Question

I have a pretty url

eg:www.mydomain.co.in to subdomain.mydomain.co.in which works perfectly fine..

The problem that I am facing is that with parameters.... I am getting subdomain.mydomain.co.in/category?id=250....This has to be changed tosubdomain.mydomain.co.in/category/250 using only .htaccess..

Yes there are many links which works for www.mydomain.co.in?id=250 to www.mydomain.co.in/250..

what change that has to be made so that I include subdomains also.The output should be like subdomain.mydomain.co.in/category/250

.htaccess file is shown below

 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]
Was it helpful?

Solution

You need 2 new rules for handling category. Try this code:

 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]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top