0
votes

Need help about how to rewrite url in apache.

How to rewrite URL A to URL B.

URL A: project1.domainname.com

URL B: domainname.com/sites/project1

Below is my configuration, but not worked:

RewriteEngine on

RewriteCond {HTTP_HOST} ^(.*)\.domainname\.com$

RewriteRule ^(.*).domainname.com$ "http://domainname.com/sites/$1/"

please leave your idea, thanks for your help

1

1 Answers

0
votes

The correct way to rewrite project1.domainname.com —> domainname.com/sites/project1 is

RewriteEngine on
RewriteCond %{HTTP_HOST} ^(.+)\.domainname\.com$
RewriteRule ^$ http://domainname.com/sites/%1

Add a trailing slash to the rule if necessary.