php - 不要重写 css 或 js 或图像文件 htaccess

标签 php css apache .htaccess mod-rewrite

我有这样一个网址:

mysite.com/1/everything

我想重写它并只获取 url 中的数字(例如上面的 1)。为此,我编写了一个 htaccess,如下所示:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule for root pages
RewriteRule (^\d+\/?([\x00-\x7F]|[^\x00-\x7F])+\/?$) index-continue.php?id=$1 [NC,L,QSA]

但是我所有的 css 文件和图像文件以及 js 文件都被重写了!我怎么解决这个问题?这会导致所有文件重写到错误的路径。

最佳答案

你的.htaccess文件应该只保留下面的东西,它将允许你的js和css直接打开路径root/css/file.css和root/js/file.js

RewriteEngine On
RewriteRule ^style/([^/.]+)?$ style/$1
RewriteRule ^js/([^/.]+)?$ js/$1
RewriteRule ^([^/.]+)/([^/.]+)?$ index-continue.php?id=$1&%{QUERY_STRING}

关于php - 不要重写 css 或 js 或图像文件 htaccess,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36906392/

相关文章:

php - 如何在本地主机和实时服务器上获得相同的 $_SERVER ['REQUEST_URI' ]

javascript - 单击 [提交,操作] 按钮时显示模式

css - 较低的百分比无法正常工作

html - css中标签的分隔线

apache - 将 http 重定向到 https,将 www 重定向到非 www

php - 动态下拉框?

php - MySQL 并非所有结果都显示

html - 为什么 h2 没有出现在页面的任何地方?

apache - 部署 Play! 2 在 Apache 或 Tomcat 中以其名称命名的路径上的应用程序

django - 无法在 Ubuntu 14.04、Apache/2.4.7、libapache2-mod-wsgi-py3、Python 3.4 virtualenv、Django 1.86 中获取语言环境编码