【发布时间】:2015-05-05 21:03:07
【问题描述】:
我正在尝试创建一个 RewriteRule,它允许我从 URL 中隐藏子文件夹名称。这似乎很简单,尽管我也想保留对父文件夹中文件的访问权限,但我不知道如何实现这一点以及这是否可能。为了更清楚一点,我的文件树如下:
[root]
L[parent]
file1
L[subfolder]
file2
所以我想做的是能够将http://example.com/parent/subfolder/file2 重写为http://example.com/parent/file2,同时仍然可以访问http://example.com/parent/file1。到目前为止,我找到了可能的解决方案 here 和 here,但它们都没有按预期工作。我还查看了 Apache Aliases,但我不确定在这种情况下是否可以使用它们。请问有什么建议吗?
编辑:这是当前的.htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /pico/
RewriteRule sitemap\.xml \?sitemap
RewriteRule ^parent?$ parent/ [R=301,L] ## Redirects the old file to the index with the same name
RewriteRule ^parent/subfolder/?$ parent/ [R=301,L] ## Redirects the index of the subfolder to the parent
RewriteRule ^old-folder/?$ parent/subfolder/new-file1 [R=301,L] ## Redirects the old index to a new file in the subfolder
RewriteRule ^old-folder/old-file parent/new-file [R=301,L] ## Redirects the files in the old folder to a new file in the parent
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
RewriteRule ^parent/([^/]+)/?$ parent/subfolder/$1 [L]
</IfModule>
# Prevent file browsing
Options -Indexes
带有cmets的规则只是示例,因为我在改变结构的同时将旧内容移动到新站点,所以还有更多重复的规则,就像上面的示例一样。
【问题讨论】:
-
您当前的 .htaccess 文件在哪里?
-
刚刚添加到问题中
标签: apache .htaccess mod-rewrite url-rewriting