问题
I'm struggling with a mod_rewrite problem. Basically I need to do a secret redirect on the domain name, going from
http://domainname.com.someotherstuff.com
to
http://domainname.com
This rule should affect all subdirectories as well.
I've understood there are three steps:
- tell the system if the path matches what we're looking for
- define the RewriteRule
- pass the new path to the old one so that the system knows (even if it doesn't show) that the two match
I've looked up several posts and resources (the closest ones being this and this) but none of them can solve both my problems – rewriting and secrecy – at once.
Can anybody point me in the right direction?
Moreover, can someone explain the tradeoff between a hidden redirect and a 301? Hidden redirect is not search engine friendly, correct?
Thanks a lot!
回答1:
referring to an older post for clarification on rewrite vs redirect
If you want the customer's browser to say http://domainname.com, but fetch the content from http://domainname.com.someotherstuff.com, then what you want is a rewrite. You will point your customer at http://domainname.com and that answering frontend (server/LB/etc...) will then rewrite "domainname.com" to "domainname.com.someotherstuff.com" and send the request on to a backend service that will answer that request. I prefer to SNAT in this case, so the backend responds directly to the frontend, which then returns the content to the customer none the wiser.
You have several moving parts here:
- DNS entries for domainname.com and domainname.com.someotherstuff.com
- frontend - F5s are my favorites, but you can achieve similar results with any linux server; needs to be able to resolve domainname.com.someotherstuff.com and has network connectivity to the backend; servicing requests for http://domainname.com
- backend - web server; servicing requests from frontend for http://domainname.com.someotherstuff.com
来源:https://stackoverflow.com/questions/30976145/secretly-do-a-mod-rewrite-on-domain-name