htaccess的通配符重定向 [英] htaccess wildcard redirect

查看:784
本文介绍了htaccess的通配符重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看了看,并没有迄今发现了类似的问题上左右。 我想重定向从www.example.com/*我的所有文件和文件夹(目录),以www.example.com/website/~~V。我目前的.htaccess是:

  RewriteEngine叙述上

#要设置自定义的php.ini,添加下面一行到本文件:
#suphp_configpath /home/yourusername/path/to/php.ini

的RewriteCond%{HTTP_HOST} ^例如\ .COM $ [OR]
的RewriteCond%{HTTP_HOST} ^ WWW \ .EXAMPLE \ .COM $
重写规则^ / $?HTTP \:\ / \ / WWW \ .EXAMPLE \ .COM \ /网站\ /[R = 301,L]
重定向301 / * http://www.example.com/website/
 

但它不能正常工作。

解决方案

 的RewriteCond%{REQUEST_URI}!^ /网站/
重写规则^ * $ http://www.example.com/website%{REQUEST_URI} [R = 301,L]
 

小记:我建议用302 code进行测试,当你感到满意的结果改变它(当然,在需要时),以301。究其原因 - 现代浏览器都缓存301重定向..所以它可能工作了,但你仍然可以看到缓存的结果

I looked and haven't thus far found a similar question on SO. I want to redirect all my files and folders (directories) from www.example.com/* to www.example.com/website/. My current .htaccess is:

RewriteEngine on

# To set your custom php.ini, add the following line to this file:
# suphp_configpath /home/yourusername/path/to/php.ini

RewriteCond %{HTTP_HOST} ^example\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.example\.com$
RewriteRule ^/?$ "http\:\/\/www\.example\.com\/website\/" [R=301,L]
Redirect 301 /* http://www.example.com/website/

However it is not working.

解决方案

RewriteCond %{REQUEST_URI} !^/website/
RewriteRule ^.*$ http://www.example.com/website%{REQUEST_URI} [R=301,L]

Small note: I suggest using 302 code for testing and when you are happy with results change it to 301 (where required, of course). The reason -- modern browsers do cache 301 redirects .. so it may work already, but you still may see cached result.

这篇关于htaccess的通配符重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆