htaccess的 - 在URL中隐藏的目录,而preserving其他文件文件、目录、htaccess、URL

2023-09-02 20:37:47 作者:勾勾手指头丶

我公司开发的工具,一个巨大的工作室,每个工具都有其自己的目录中/工具/文件夹。所以,如果你有一个工具叫的例如的,网址是/工作室DIR /工具/例如/.

I developed a giant studio of tools and each tool has its own directory in the /tools/ folder. So if you have a tool named example, the URL would be /studio-dir/tools/example/.

我试图隐藏URL中/工具/目录下,同时使/工具/目录以外确保其他文件仍然有效。例如,的index.php文件和/管理/目录应该保留。

I'm trying to hide the /tools/ directory from URLs, while making sure other files outside of the /tools/ directory still work. For example, the /index.php file and /admin/ directory should remain.

我想这一点,但它不仅造成大量的404错误的一切。我知道它可能WAAY了,我吸用重写URL。 :P

I tried this, but it only caused massive 404 errors on everything. I know it's probably waay off, I suck with rewriting URLs. :P

RewriteCond %{REQUEST_URI} !^/tools/
RewriteRule ^/?([^/]+)$ /tools/$1 [L]

如果你还是有疑惑,我想:

If you're still confused, I want:

http://www.example.com/studio/ 工具/例子/的index.php

要能够加载的:

http://www.example.com/studio/ 为例/索引。 PHP

虽然仍保持/工具/目录下,并允许其他文件/工具/目录加载之外。

Whilst still keeping the /tools/ directory, and allowing other files outside of the /tools/ directory to load.

这可能吗?

推荐答案

您将需要的东西是这样的:

You will need something like this:

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule    /studio/(.*) /studio/tools/$1    [L]
 </IfModule>

的问题是,它不会工作,如果requestet文件是既在工作室-文件夹和工具夹。

The problem is that it will not work, if the requestet file is both in the studio-folder and the tools-folder.

但会有没有办法prevent这一点,因为服务器永远不会,现在如果一个URL被意指/工作室/工具/或/工作室/

But there will be no way to prevent this, as the server never can now if an url is meant to refer to /studio/tools/ or /studio/

编辑:您可以删除/工具/从可见的网址是这样的:

You can remove /tools/ from the visible urls like this:

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule    /studio/(.*) /studio/tools/$1    [L]
    RewriteRule    /studio/tools/(.*) /studio/$1    [L,R=302]
 </IfModule>