简体   繁体   中英

How to hide subfolder name from script url

I want to hide subfolder name from script url:

<link rel="stylesheet" type="text/css" href="/abc/cde/css/bootstrap.min.css" />

I want to change href="/abc/cde/css/bootstrap.min.css"

To

href="/css/bootstrap.min.css"

Descriptions:

I am using shared hosting. And my site is inside folder abc/cde/

I am using following .htaccess at root folder(/)

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] 

Everthing seems Okay .I am able to access www.myhost.com directly.

But

when I am using (View source), Subfolder as visible there

<link rel="stylesheet" type="text/css" href="/abc/cde/css/bootstrap.min.css" /> 

I want to hide This path also.

FYI:I am using Cakephp

Rewrite rule cannot change your HTML source. You need to change your script tag as below:

<link rel="stylesheet" type="text/css" href="/css/bootstrap.min.css" /> 

Then have your rules as below:

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] 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM