htaccess mod_rewrite hostname

让人想犯罪 __ 提交于 2020-01-04 02:44:26

问题


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

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)

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 )


回答1:


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]


来源:https://stackoverflow.com/questions/13021893/htaccess-mod-rewrite-hostname

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