如何防止在输入url时重定向到子域


How to prevent redirecting to subdomain when enter url?

这很难解释,但我正在为我正在制作的路由器/框架重写url。我将我的根目录指向一个名为public的文件夹,并在该文件夹中处理index.php等的重写。但是我希望能够访问css和js文件夹。无论如何,每当我转到/css时,它都会将我带到/public/css,并允许我查看文件和列表目录,但当我查看文件时,它允许我在不更改URL的情况下查看文件。所以基本上,如果有人去/css,我希望它保持原样,而不是改为/public/css。

root.htaccess文件

RewriteEngine On
RewriteBase /
RewriteRule ^$ /public/ [L]
RewriteCond %{REQUEST_URI} !^/public/
RewriteRule ^(.*)$ /public/$1

公用.htaccess文件

<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
    Options -MultiViews
</IfModule>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

将您的root.htaccess更改为:

RewriteEngine On
RewriteBase /
RewriteRule ^$ public/ [L]
RewriteCond %{REQUEST_URI} !^/(public|css|js)/ [NC]
RewriteRule ^(.*)$ public/$1 [L]

现在这个重写规则不会影响/css//js/文件夹。