简体   繁体   中英

Redirect to a subdirectory with .htaccess

I'm following a tutorial and I have a redirect problem.

I'm running ubuntu 16.04.

The project file is located in the /var/www/html directory and is named tuto

My directory tuto has the following directories: /controller , /view , /model , /core and webroot and as file it has index.php and .htaccess

The webroot directory has the following directories: /css , /img , /js and as index.php file

I would like that, when this url: //localhost/tuto/css/style.css is entered, that the .htaccess file will look it up in the webroot/css/style.css

How do I code this?

You should simply redirect that specific file in the htaccess file. i assume you have in it few redirections so put it before all of them:

RewriteEngine On

RewriteRule ^css/style.css webroot/css/style.css [QSA,NC]

and in your html code just call it as:

<link rel="stylesheet" href="css/style.css">

You could do what they've suggested, it might make conflicts with your other htaccess rewrite rules. i would just go simple and do

RewriteEngine On

RewriteRule ^css webroot/css [QSA,NC]
RewriteRule ^js webroot/js [QSA,NC]

then every link to the css/js folders will actually call webroot folder

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