这是我想做的事:mod_rewrite的与子域下划线替换破折号然后重定向
- 我想要替换所有破折号 - 用下划线(_),但只有在子域()。
- 毕竟破折号代替我想重定向到一个子目录与重写的子域
例如名称: http://subdomain-with-dashes.rotarytest.de/a-directory/an-image.png 重写后应 http://rotarytest.de/subdomain_with_dashes/a-directory/an-image.png
这里是我的权利现在,请参阅代码中的注释
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]
我尝试了几乎所有我在这里找到的解决方案stackoverflow或网络上,但他们都没有正常工作。
有人可以帮我吗?先谢谢你。
这是什么意思,当规则3只是将该子域重定向到mydomain.de/subdomain-name? – Gerben 2013-03-15 14:17:58
正如你可以在我的评论中看到的,我首先想用下划线替换破折号,然后将重写的子域重定向到一个文件夹:http://mydomain.de/subdomain_previously_with_dashes/a-directory/an-image.png – jmartsch 2013-03-18 11:06:12