我想从脚本 url 中隐藏子文件夹名称:
<link rel="stylesheet" type="text/css" href="/abc/cde/css/bootstrap.min.css" />
我想更改 href="/abc/cde/css/bootstrap.min.css"
自
href="/css/bootstrap.min.css"
描述:
我正在使用共享主机。我的网站在文件夹 abc/cde/
我在根文件夹(/)使用以下.htaccess
。Options -Indexes
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?myhost.com$
RewriteCond %{REQUEST_URI} !^/abc/cde/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /abc/cde/$1
RewriteCond %{HTTP_HOST} ^(www.)?myhost.com$
RewriteRule ^(/)?$ abc/cde/index.php [L]
一切似乎都还好.我可以直接访问 www.myhost.com。
但
当我使用(查看源代码)时,子文件夹在那里可见
<link rel="stylesheet" type="text/css" href="/abc/cde/css/bootstrap.min.css" />
我也想隐藏这条路。
仅供参考:I我正在使用蛋糕
重写规则无法更改您的 HTML 源代码。您需要更改脚本标记,如下所示:
<link rel="stylesheet" type="text/css" href="/css/bootstrap.min.css" />
然后制定如下规则:
Options -Indexes
RewriteEngine on
# to route css and js
RewriteRule ^(css|js)/ /abc/cde%{REQUEST_URI} [L,NC]
RewriteCond %{HTTP_HOST} ^(www'.)?myhost'.com$
RewriteCond %{REQUEST_URI} !^/abc/cde/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /abc/cde/$1 [L]
RewriteCond %{HTTP_HOST} ^(www'.)?myhost'.com$
RewriteRule ^/?$ abc/cde/index.php [L]