htaccess将文件夹重定向到子文件夹

编程入门 行业动态 更新时间:2024-10-21 18:37:54
本文介绍了htaccess将文件夹重定向到子文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

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

我需要从

www.domain/folder1

www.domain/folder1/subfolderA

注意:folder1是空的。在子文件夹A中,我有index.html,index.php,css文件,js文件。如果我转到 www.doman/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/folder1/subfolderA/" I see a simple web page with correct css and js provided by index.php file.

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

My .htaccess file is in www.domain/ (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: stackoverflow/a/32525136/1315873) ('R' is just for debug)

结果: www.domain/folder1/subfolderA/subfolderA/subfolderA/subfolderA/subfolderA /

Results: www.domain/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/folder1/subfolderA/subfolderA/subfolderA/subfolderA/subfolderA(未更改)

Perfect for htaccess.madewithlove.be/ but not for my server. Results: www.domain/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/folder1/),因此我删除了

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

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

I hope it can be of help to someone else.

更多推荐

htaccess将文件夹重定向到子文件夹

本文发布于:2023-10-31 13:04:41,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1546168.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件夹   重定向   htaccess

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!