.htaccess : Rewriting initial output back into subdomain

删除回忆录丶 提交于 2019-12-24 10:35:14

问题


I have the following htaccess.

Options +FollowSymlinks 
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} !^(www|m)\.DOMAIN\.com$
RewriteCond %{HTTP_HOST} ^([^\.]+).DOMAIN.com$
RewriteRule ^(.*)$ http://DOMAIN.com/index.php?id=%1 [NC,QSA,L,R=301]

The problem is that although it works I need it to still use the subdomain as the URL. So basically now I'm trying to rewrite DOMAIN.com/index.php?id=%1 back into SUDOMAIN.DOMAIN.com so the user sees the subdomain they requested on the address bar and not the http://domain.com/index.php?id=user

I'ver tried all sorts of things but always end up with some sort of infinite loop. Please help!


I already have a wildcard subdomain set up. In conjunction with the htaccess shown above. The submain doesn't stick, it rewrites itself into the long string shown above. But what im trying to do is get the url ro remain subdomain.domain.com unfortunately the link you posted does peretty much the same as what I have posted above, doesn't really seem to be able to get the sub-domain to stick.

Any ideas?


回答1:


Not sure if you figured it out yet, but your last line (I believe) should be this:

RewriteRule ^(.*)$ index.php?id=%1 [NC,QSA,L,R=301]

If that does not work try this:

RewriteRule (.*) index.php?id=%1 [NC,QSA,L,R=301]

No expert but I have subdomains working from some other code I found. Hope it helps.




回答2:


You need to change your DNS settings before. (A record)

There is already an answer for that question.



来源:https://stackoverflow.com/questions/7430237/htaccess-rewriting-initial-output-back-into-subdomain

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!