這是我想做的事: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