问题描述
我想创建一个干净的 url,例如,我有一个网站 www.mywebsite.com,我想要,如果有人尝试 http://www.mywebsite.com/something,他应该被重定向到 www.mywebsite.com,
i want to create a clean url, as in, let say, i have a site www.mywebsite.com, i want, if anybody tries http://www.mywebsite.com/something, he should get redirected to www.mywebsite.com,
所以任何在 mywebsite.com/之前输入的内容都应该被重定向到 www.mywebsite.com
so any thing that is typed ahead of mywebsite.com/ they should get redirected to www.mywebsite.com
我如何在 .htaccess 中执行此操作,请帮忙.
how can i do this in .htaccess, kindly help.
推荐答案
RewriteEngine ON
RewriteRule ^/.+ / [L,R]
这会将所有内容重定向到/作为永久重定向.看看 http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html 有关您可以为透明度等添加的标志的更多信息.
That will redirect everything to / as a permanent redirect. Look at http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html for more information on the flags you can add for transparency etc etc.
如果您想在 .htaccess
中使用它,请确保您的 <VirtualHost >
配置中有正确的覆盖指令.
If you want this in .htaccess
make sure you have the correct override directives in your <VirtualHost >
config.
这篇关于.htaccess 重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!