简体   繁体   English

如何为多部分网址调整.htaccess

[英]How to adjust .htaccess for multi-part URL

I am trying to get my code to accept an URL like the following: 我正在尝试让我的代码接受如下所示的URL:

www.mysite.com/something/something2/something3/something4 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: 我在.htaccess中使用了以下代码,因此请求是通过index.php文件运行的:

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. 如果该网址为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. 但是,如果我将其更改为www.mysite.com/something/something2,则在加载外部文件(例如CSS)时会遇到问题。

Instead of loading the requested CSS file, it loads index.php. 而不是加载请求的CSS文件,而是加载index.php。

This is only if there is more than 1 segment after the domain. 仅当域后有1个以上段时。 Otherwise, it loads the CSS just fine. 否则,它会很好地加载CSS。

Here is how I am loading the CSS: 这是我加载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 . 由于您要告诉Apache将所有URI都视为index.php ,因此所有路径都必须是绝对路径或相对于index.php路径。 For example: 例如:

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

(Originally commented) (原评论)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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