htaccess的mod_rewrite的主机名主机名、htaccess、mod_rewrite

2023-09-02 20:34:56 作者:笶傲葒塵

如何改写域名网址到一个特定的域名,如果它没有与之相匹配的。

How can i rewrite the domain url to a specific domain name if it didnt match it ..

比方说,我希望它只匹配example.com 和访问者来自服务器的ip(http://127.0.0.1/something/else)或来自另一个域(http://domain.com/something/else)

Let's say i want it to only match example.com and the visitor came from server ip (http://127.0.0.1/something/else) OR came from another domain (http://domain.com/something/else)

我怎么能改写域名,并保留所有的其他参数,只是域名example.com(结果应该是:的 http://example.com/somthing/else )

how can i rewrite the domain name and keep all the other parameters, just domain name to example.com ( result should be : http://example.com/somthing/else )

推荐答案

尝试在你的文档根目录下添加这些规则的htaccess文件:

Try adding these rules to the htaccess file in your document root:

RewriteEngine On
RewriteCond %{HTTP_HOST} !^(www.)?example.com$ [NC]
RewriteRule ^(.*)$ http://example.com/$1 [L,R]