简体   繁体   English

.htaccess网址重写子网址的问题

[英].htaccess url rewrite issue for sub url

Here is my .htaccess rule 这是我的.htaccess规则

<IfModule mod_rewrite.c>
    RewriteEngine On 
    RewriteRule ^(.*)$ public/$1 [L]
</IfModule>

It will construct 'public' for all the requests. 它将为所有请求构造“公共”。

After using this it works for good for 使用后,它对

site.com/home , site/blog site.com/home,网站/博客

but while i start to use 但是当我开始使用

site/blog/data 网站/博客/数据

it does not load the css as it is a sub directory 它不加载css,因为它是子目录

How can i rewrite the url to make this work 我该如何重写网址以使其正常工作

 RewriteRule ^(.*)$ public/blog$1 [L]

Update 更新

For the first probablity 对于第一次概率

ie, domain.com/blog the css will be site.com/css/style.css 即,domain.com / blog的CSS将是site.com/css/style.css

and while in the next probablity 而在下一个概率中

ie, domain.com/blog/data the css will be site.com/blog/css/style.css 即,domain.com / blog / data的CSS将是site.com/blog/css/style.css

which is expected as site.com/css/style.css for the second probablity also 预计第二个概率也将是site.com/css/style.css

How can i do this ? 我怎样才能做到这一点 ?

Since you don't want to show me your code I can only guess here... 由于您不想向我展示您的代码,所以我只能在这里猜测...
I suppose the problem's that you include the css file like that: 我想问题是您包括这样的css文件:

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

This means the path is relative to the current URL. 这意味着该路径是相对于当前URL的。 What you need to do to make it work on every "level" is use an absolute path or at least one that's relative to the site root (domain) 要使它在每个“级别”上都起作用,您需要做的是使用绝对路径或至少一个相对于站点根目录(域)的路径

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

Or just use the Laravel asset() function that generates a full url 或者只是使用生成完整网址的Laravel asset()函数

<link rel="stylesheet" type="text/css" href="{{ asset('css/style.css') }}"/>

Or even one step further, use HTML::style() to generate the full include code 甚至更进一步,请使用HTML::style()生成完整的包含代码

{{ HTML::style('css/style.css') }}

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

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