0

Currently my Url is: http://www.domain.co.uk/index.php/city/details/city-name

I would like to change it to:

http://www.city-name.domain.co.uk/index.php/city/details/city-name

or:

http://www.city-name.domain.co.uk/city/details/city-name

1 Answer 1

1

Put the .htaccess file into the http ://www.domain.co.uk/ document root

To http ://www.city-name.domain.co.uk/index.php/city/details/city-name

RewriteRule ^(.*)/([^/]+)$ http://www.$2.domain.co.uk/$1/$2 [R=301,L]

To http ://www.city-name.domain.co.uk/index.php/city/details/city-name

RewriteRule ^index.php/(.*)/([^/]+)$ http://www.$2.domain.co.uk/$1/$2 [R=301,L] 

If the server is the same, set above RewriteRule this line to prevent redirection loop

RewriteCond %{HTTP_HOST} !^www\.(.*).domain\.co\.uk [NC]  

File content example

<ifModule mod_rewrite.c>
   RewriteEngine on
   RewriteCond %{HTTP_HOST} !^www\.(.*).domain\.co\.uk [NC]  
   RewriteRule ^index.php/(.*)/([^/]+)$ http://www.$2.domain.co.uk/$1/$2 [R=301,L]  
</IfModule>

To exclude domain.co.uk (whitout www)

<ifModule mod_rewrite.c>
   RewriteEngine on
   RewriteCond %{HTTP_HOST} !^www\.(.*).domain\.co\.uk [NC]
   RewriteCond %{HTTP_HOST} !^domain\.co\.uk [NC]  
   RewriteRule ^index.php/(.*)/([^/]+)$ http://www.$2.domain.co.uk/$1/$2 [R=301,L]     
</IfModule>
Sign up to request clarification or add additional context in comments.

3 Comments

but one more problem is there. now CSS and image paths is not working
please, could you put a example of css and image path?
there is problem. the code u said is not working. there is subdomain with same name that worked when did rewrite..so i just wanna replace url no need to redirect. ur code is redirecting domain.co.uk/index.php/city/details/city-name to city-name.domain.co.uk Can u give me a code that is url replacing code??

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.