Mod rewrite .htaccess重写赢得';在某些情况下不能加载css

Mod rewrite .htaccess重写赢得';在某些情况下不能加载css,mod-rewrite,Mod Rewrite,这是我的重写规则: RewriteEngine On RewriteCond %{REQUEST_FILENAME}.php -f RewriteCond %{REQUEST_URI} !/$ #RewriteRule (.*)/?$ $1\.php [L] RewriteRule profile/ profile.php RewriteRule profile profile.php 我在这方面有点新,但是当我转到localhost/profile时,一切都加载得很好,但是当我转到loca

这是我的重写规则:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_URI} !/$
#RewriteRule (.*)/?$ $1\.php [L]
RewriteRule profile/ profile.php
RewriteRule profile profile.php
我在这方面有点新,但是当我转到localhost/profile时,一切都加载得很好,但是当我转到localhost/profile/时,实际的页面加载了,但是css没有加载,我必须手动将其更改为/style.css以便加载,有人知道我如何在最后将/at设置为可选时做到这一点吗(无需放置我的整个域或绝对路径)?谢谢。

您可以试试这个

但这不是最好的解决方案。你可以定义一个全局变量,用它来给出绝对路径

<?php 
//at the beginning of your page
define('LINK',"http://localhost/");

//for your css href
echo LINK."style.css";

你必须给出css的原始路径吗?你想加载什么,style.css还是profile.php?规则集指出是最后一个,我猜这一个反过来调用第一个,但我只是猜测。很难理解当
时会发生什么,“…一切都加载良好…”
@FelipeAlamedaA不会加载任何外部文件,例如style.css或任何图像,因为当我使用localhost/profile/时,它认为这是一个新的目录,但它在localhost/profile/上工作得非常好,我只是不想将所有内容都改为/style.css而不是style.css,它可能会变得非常混乱,所以我只想得到一个新的重写规则,可以无需创建“新目录”即可工作@user1925957然后,style.css不会加载尾随斜杠URI,因为调用该文件时指向该文件的路径是错误的。也许这会有所帮助。我尝试过,手动更改了每个文件中的所有链接,但更糟的是,当我转到/profile/时,它加载得很好,只是在侧栏上,应该在第一个位置转到/profile/e、 它将要/profile/profile/,只是变得太乱了,我想我不会使用/profile/url,只是/profile,我希望有一个更简单的方法来完成这一切_rewrite@user1925957我用mod_rewrite开发了一些项目,我使用了绝对路径。每次都很好。