htaccess将文件夹重定向到子文件夹 [英] htaccess redirect folder to subfolder

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

问题描述

我知道这似乎是一个重复的问题:我进行了很多搜索,应用了数十个重写规则,但它们不起作用。

I know it seems duplicated question: I searched a lot, I applied tens of rewrite rules but they don't work.

我需要从

www.domain.com/folder1

www.domain.com/folder1/subfolderA

注意:folder1是空的。在子文件夹A中,我有index.html,index.php,css文件,js文件。如果我转到 www.doman.com/folder1/subfolderA/,则会看到一个简单的网页,其中包含index.php文件提供的正确的CSS和JS。

Note: folder1 is emtpy. in subfolderA I have index.html, index.php, css file, js files. If I go to "www.doman.com/folder1/subfolderA/" I see a simple web page with correct css and js provided by index.php file.

我的.htaccess文件位于www.domain.com/中(我试图将其放在folder1中,但它不起作用,甚至删除了 RewriteBase /行)。文件权限:0755。

My .htaccess file is in www.domain.com/ (I've tried to put it in folder1 but it doesn't work, even removing "RewriteBase /" line). File permssions: 0755.

选项-索引,选项+索引生成错误此处不允许使用选项索引,因此我将其删除。

Options + FollowSymLinks生成错误这里不允许使用Option FollowSymLinks,我将其删除。

"Option -Indexes","Option +Indexes" generate error "Option indexes not allowed here", so I deleted them.
"Options +FollowSymLinks" generates error "Option FollowSymLinks not allowed here" and I deleted it.

RewriteBase /
RewriteRule ^/folder1(/.*)?$ /folder1/subfolderA$1 [L,R]
(rif: https://stackoverflow.com/a/32525136/1315873) ('R' is just for debug)



结果:

www.domain.com/folder1/subfolderA/subfolderA/subfolderA/subfolderA/subfolderA /


Results:
www.domain.com/folder1/subfolderA/subfolderA/subfolderA/subfolderA/subfolderA/

RewriteBase /
RewriteCond %{HTTP_HOST} !subfolderA [NC]
RewriteRule ^/folder1(/.*)?$ /folder1/subfolderA$1 [L,R]

对于 http://htaccess.madewithlo ve.be/ ,但不适用于我的服务器。
结果:

www.domain.com/folder1/subfolderA/subfolderA/subfolderA/subfolderA/subfolderA(未更改)

Perfect for http://htaccess.madewithlove.be/ but not for my server. Results:
www.domain.com/folder1/subfolderA/subfolderA/subfolderA/subfolderA/subfolderA (unchanged)

RewriteBase /
RewriteCond %{HTTP_HOST} !subfolderA [NC]
RewriteRule ^/folder1/$ /folder1/subfolderA/ [L,R]

结果:

禁止访问

日志中说:没有匹配的DirectoryIndex(index.html,index.htm,index.php,index.php3,index.phtml,index.shtml,index。 wml),并且由选项指令禁止的服务器生成的目录索引

Results:
Forbidden
Log says: "No matching DirectoryIndex (index.html,index.htm,index.php,index.php3,index.phtml,index.shtml,index.wml) found, and server-generated directory index forbidden by Options directive"

如果我添加到网址 index.php或 index.html结果是 404 Not found(实际上是真的)。​​

If I add to the url "index.php" or "index.html" the result is "404 Not found" (that's true actually).

我不知道该怎么办。希望能对您有所帮助。

这是不可能的重定向吗?

谢谢。

I don't know what else to do. I hope in your help.
It's an impossibile redirect to do?
Thank you.

推荐答案

我找到正确的方法:P
.htaccess文件如下所示:

I find the right way to do :P The .htaccess file look like this:

RewriteBase /
RewriteCond %{REQUEST_URI} !subfolderA [NC]
RewriteRule ^/?folder1(/.*)?$ /folder1/subfolderA$1 [L,R]

由于我不会在浏览器中更改网址(必须看到 www.domain.com/folder1/),因此我删除了

As I don't wont to change url in browser (one must see "www.domain.com/folder1/"), I remove ",R" from last line.

我希望它可以对其他人有所帮助。

I hope it can be of help to someone else.

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

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