使用.htaccess隐藏子文件夹时遇到问题


Having trouble hiding subfolder with .htaccess

我正在尝试删除我的url的url.com/php/(/php/)部分,并尝试使用htaccess和以下行

RewriteCond %{REQUEST_URI} !^/php
RewriteRule (.*) /php/$1 [QSA,L]

但在服务器上收到此错误:

在此服务器上找不到请求的URL/php/index.php。

实际上,在每个场景中,它都在我的url.com地址后面添加/php/。我尝试过很多其他线程,结果都不一样,但这一个实际上从url中删除了/php/,只是在这种情况下,假设/php/每次都属于那里。关于如何解决这个问题有什么想法吗?

感谢

编辑:现在我想起来了,我实际上正在试图重写整个文件夹树,这样只显示文件名和url。

那么url.com/php/ra/file.php呢?id=1显示为url.com/file.php?id=1

我的整个htaccess文件以消除混乱:

# Use PHP5.4 Single php.ini as default
AddHandler application/x-httpd-php54s .php
Options -Indexes +FollowSymLinks -MultiViews
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://urlreplaced.com/$1 [R,L]
RewriteCond %{REQUEST_URI} !^/php
RewriteRule (.*) /php/$1 [QSA,L]

第二版:对造成的混乱表示歉意。

我的网站网址是:https://www.url.com

当前/php/是下一级其中是/ea/、/hbu/、/hc/、/ra/、/st/和/tut/

php包含很多文件,但都以.php结尾,并接受GET vars

以及每个目录,每个目录中可能有100个.php文件。如果我正确理解到目前为止我所读到的关于这个问题的内容,那么子目录后的$1是否涵盖了其中的哪些文件?

我需要/php/目录之后的任何和所有文件在URL中显示为URL.com/example.php?var=x,不管哪个子目录超过这个值。

因此,无论example.php存在于/php/ra或/php/hbu中,还是仅存在于plain-php中,它仍然相当于url.com/example.php

感谢您的帮助

根据您在编辑中提供的URL,如果您只想从URL中删除PHP路径并保留文件名和查询字符串,您可以这样做。

 RewriteEngine On
 #rewrite http to https
 RewriteCond %{HTTPS} off
 RewriteRule ^(.*)$ https://urlreplaced.com/$1 [R=301,L]
 #if full real URL is used, redirect to file.php
 RewriteCond %{THE_REQUEST} [A-Z]{3,}' /+php/ra/file'.php'?id=([^&' ]+)
 RewriteRule ^ file.php?id=%1 [R=301,L]
 #if request is a real file or directory do nothing
 RewriteCond %{REQUEST_FILENAME} -f [OR]
 RewriteCond %{REQUEST_FILEMAME} -d
 RewriteRule ^ - [L]
 #rewrite full path to file.php
 RewriteCond %{QUERY_STRING} ^id=(.+)$
 RewriteRule ^file'.php$ /php/ra/file.php?id=%1 [L]

所以现在你的URL可以是这样的。

http://example.com/file.php?id=30