简体   繁体   中英

How to adjust .htaccess for multi-part URL

I am trying to get my code to accept an URL like the following:

www.mysite.com/something/something2/something3/something4

I have used the following code in my .htaccess so requests are run through an index.php file:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php [L]

This works fine if the url is www.mysite.com/something.

However, if I change it to www.mysite.com/something/something2 I get a problem loading external files such as CSS.

Instead of loading the requested CSS file, it loads index.php.

This is only if there is more than 1 segment after the domain. Otherwise, it loads the CSS just fine.

Here is how I am loading the CSS:

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

Since you're telling Apache to treat all URIs as index.php , all your paths will need to be absolute, or relative to index.php . For example:

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

(Originally commented)

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