重定向到另一个文件夹 [英] Redirect to another folder

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

问题描述

我读这<一href="http://stackoverflow.com/questions/990392/htacces-rewrite-to-redirect-root-url-to-subdirectory">.htaccess改写重定向根URL子目录,然后我试图达到同样的事情。

I read this .htaccess rewrite to redirect root URL to subdirectory and i'm trying to achieve the same things.

大多数选票的解决方案是:

The solution with most up votes was:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^example\.com$
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
RewriteRule ^$ store [L]

现在,看着它似乎运作良好的意见。 问题是,我想不是要拼命code的任何路径(如,而不是上面的www.example.com提供)。我想,我的的.htaccess 项目名称/ 重定向到项目名称/公/ 尽管真正的服务器主机是什么。所以,如果我把项目名称/ www.pinco.com 的根服务器里面重定向到 www.pinco.com/projectname/public / ,但它显示了 www.pinco.com/projectname /

Now, looking at the comments it seems to be working good. The problem is that I'd like not to hardcode any path (as instead provided above "www.example.com"). I'd like that my .htaccess inside projectname/ redirects to projectname/public/ despite what the real server host is. So that if I put projectname/ inside the root server of www.pinco.com it redirects to www.pinco.com/projectname/public/ but it shows www.pinco.com/projectname/.

我怎样才能做到这一点?

How can I achieve that?

推荐答案

您发现这个例子实际上是做两件不同的事情。

The example you found is actually doing two different things.

# This is actually just redirecting all http://example.com/somepage/
# to http://www.example.com/somepage/, to ensure all URLs have the www.
RewriteCond %{HTTP_HOST} ^example\.com$
RewriteRule (.*) http://www.example.com/$1 [R=301,L]  

第二重写是什么将帮助你实现你想要做的事情。

The second rewrite is what will help you achieve what you're trying to do.

# This redirect all requests for http://example.com -> http://example.com/newdir
# If you are looking to redirect the request, so the URL contains directory name,
# you can change the [L] to [R=301,L]
RewriteRule ^$ /newdir [L]

# If your concerned about direct access to a particular page without the sub-dir 
# you will want to add something like this
RewriteCond %{REQUEST_URI} !^/newdir
RewriteRule (.*) /newdir$1 [R=301,L]

所以,在这种情况下,你不会有与该应用程序运行在域予以关注。

So, in that case, you won't have to be concerned with domain that the application is running on.

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

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