如何强制用于路由不航线的.css,.js文件,JPG格式等文件的.htaccess? [英] How to force .htaccess used for routing to not route .css, .js, .jpg, etc. files?

查看:238
本文介绍了如何强制用于路由不航线的.css,.js文件,JPG格式等文件的.htaccess?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个的以下.htaccess文件子目录的一个网站,让我的路线的所有URL的index.php,我可以解析他们。

不过,这不是让我需要的网站的标准文件,如: CSS,JavaScript的不同,PNG等。

什么我需要改变(我假设在第四行),允许这些文件,这样他们就不会被路由到index.php?

  RewriteEngine叙述上
的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d
的RewriteCond $ l ^(指数\ .PHP |公众| CSS | JS | PNG | JPG | GIF |机器人\ .TXT)!
重写规则^(。*)$的index.php / PARAMS = $ 1 [L,QSA]
的ErrorDocument 404的index.php
 

解决方案

东西,我注意到了。你使用的是问号正斜杠,而不是...的PARAMS重定向通常是这样的:

 重写规则^(。*)$的index.php?PARAMS = $ 1 [L,QSA]
 

这应该由自己的工作,因为任何这些文件*应*是真实的文件。

 的ErrorDocument 404的index.php

RewriteEngine叙述上
的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d
重写规则^(。*)$的index.php?PARAMS = $ 1 [L,QSA]
 

要具备网站忽略特定的扩展,你可以添加一个条件,忽略大小写,只检查请求的文件名末尾:

  RewriteEngine叙述上

!的RewriteCond%{REQUEST_URI}(\ CSS | \ .js文件| \巴纽| \ JPG格式| \ .gif注意|机器人\ .txt)的$ [NC]
的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d
重写规则^(。*)$的index.php?PARAMS = $ 1 [L,QSA]
 

如果你想忽略一个文件夹,那么你可以添加:

  RewriteEngine叙述上

的RewriteCond%{REQUEST_URI}!(公开| CSS)
!的RewriteCond%{REQUEST_URI}(\ CSS | \ .js文件| \巴纽| \ JPG格式| \ .gif注意|机器人\ .txt)的$ [NC]
的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d
重写规则^(。*)$的index.php?PARAMS = $ 1 [L,QSA]
 

I have the following .htaccess file in a subdirectory of a site which allows me to route all URLs to index.php where I can parse them.

However, it's not allowing the standard files that I need for the website, e.g. css, javascript, pngs, etc.

What do I need to change (I assume in the fourth line) to allow these files so they don't get routed to index.php?

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|public|css|js|png|jpg|gif|robots\.txt)
RewriteRule ^(.*)$ index.php/params=$1 [L,QSA]
ErrorDocument 404 /index.php

解决方案

Something I noticed. You're using the forward slash instead of a question mark... the params redirect would normally look like this:

RewriteRule ^(.*)$ index.php?params=$1 [L,QSA]

This should work by itself since any of those files *should* be real files.

ErrorDocument 404 /index.php    

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?params=$1 [L,QSA]

To have the site ignore specific extensions you can add a condition to ignore case and only check the end of the filenames in the request:

RewriteEngine On

RewriteCond %{REQUEST_URI} !(\.css|\.js|\.png|\.jpg|\.gif|robots\.txt)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?params=$1 [L,QSA]

If you're trying to ignore a folder then you could add:

RewriteEngine On

RewriteCond %{REQUEST_URI} !(public|css)
RewriteCond %{REQUEST_URI} !(\.css|\.js|\.png|\.jpg|\.gif|robots\.txt)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?params=$1 [L,QSA]

这篇关于如何强制用于路由不航线的.css,.js文件,JPG格式等文件的.htaccess?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆