.htaccess中的mod_rewrite挡住了我的CSS我的、住了、htaccess、mod_rewrite

2023-09-02 10:08:04 作者:浅浅的海雾

获得htaccess的重写我的链接,这样更好的搜索引擎优化:

 选项+了FollowSymLinks -MultiViews
RewriteEngine叙述上
的RewriteBase /
的RewriteCond%{REQUEST_URI} * /([^ /] +)/? [NC]
的RewriteCond%{REQUEST_URI}!指数 .PHP [NC]
重写规则。* /index.php?cat=%1 [L,NC,QSA]
 

这重写

  http://www.example.com/any/number/of/directories/lastDir
 

  http://www.example.com/index.php?cat=lastDir
 
玩家口中的宝藏江湖 曾登顶免费榜的硬核武侠手游终于公测

但我的CSS心不是工作,当我上传htaccess的到服务器上,也只是没有图像和css纯文本

尝试添加基本标记转换为HTML,但它不工作

 <基地的HREF =htt​​p://www.example.com/>
 

解决方案

尝试使用

 选项+了FollowSymLinks -MultiViews
RewriteEngine叙述上
的RewriteBase /
的RewriteCond%{REQUEST_URI} * /([^ /] +)/? [NC]
的RewriteCond%{REQUEST_URI} ^!(指数 .PHP |机器人 .TXT |张图片|字体| JS | CSS |脚本)[NC]
重写规则。* /index.php?cat=%1 [L,NC,QSA]
 

这将过滤掉某些类型的文件和目录,以确保资产不被重定向

Got htaccess rewriting my links for better seo like this:

Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI}  .*/([^/]+)/?     [NC]
RewriteCond %{REQUEST_URI}  !index.php      [NC]
RewriteRule  .*      /index.php?cat=%1 [L,NC,QSA]

which rewrites

http://www.example.com/any/number/of/directories/lastDir

to:

http://www.example.com/index.php?cat=lastDir

but my css isnt working, when i upload htaccess to the server, there is just plain text without images and css

tried adding base tag into html, but its not working

<base href="http://www.example.com/">

解决方案

try using

Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI}  .*/([^/]+)/?     [NC]
RewriteCond %{REQUEST_URI} !^(index.php|robots.txt|img|font|js|css|scripts) [NC]
RewriteRule  .*      /index.php?cat=%1 [L,NC,QSA]

this will filter out certain file types and directories to make sure that assets are not redirected