Here is what i want to do:
- I want to replace all dashes (-) with underscores (_) but only in subdomains.
- After all dashes are replaced i want to redirect into a subdirectory with the name of the rewritten subdomain
For example: http://subdomain-with-dashes.rotarytest.de/a-directory/an-image.png after rewrite should be http://rotarytest.de/subdomain_with_dashes/a-directory/an-image.png
Here is what i have right now, please see comments in code
RewriteEngine on
# replace dashes with underscores
# this works, but only for the last dash
RewriteCond %{HTTP_HOST} ^(.*)-(.*)$
RewriteRule ^(.*)$ http://%1_%2/$1 [L,R=301]
# if a subdomain is called, redirect to subdirectory
# this code works but only when i have one dash in my subdomain
RewriteCond %{HTTP_HOST} ^(.*)\.rotarytest\.de$
RewriteRule ^(.*)$ http://rotarytest.de/%1%{REQUEST_URI} [L,R=301]
I tried almost every solution i found here on stackoverflow or on the web, but none of them worked correctly.
Can someone help me out? Thank you in advance.