Apache的重定向 - 的.htaccess - 的RewriteCond重定向、Apache、RewriteCond、htaccess

由网友(有何不可)分享简介:我想操纵我的博客服务器上的.htaccess文件,以允许同时允许其他人访问重定向某些内容。I'm trying to manipulate the .htaccess file on my blogs server to allow certain content to be redirected while all...

我想操纵我的博客服务器上的.htaccess文件,以允许同时允许其他人访问重定向某些内容。

I'm trying to manipulate the .htaccess file on my blogs server to allow certain content to be redirected while allowing others to be accessed.

我想这样做,是让与的扩展名的文件(GIF | JPG | CSS | JS | ICO | PNG)将连同访问目录 /包括/ 和文件 sitemap.html ,而所有其他流量,我想发送给sitemap.html文件。

What I would like to do, is allow any file with the extension of (gif|jpg|css|js|ico|png) to be accessed along with a directory /includes/ and a file sitemap.html while all other traffic I would like to send to the sitemap.html file.

这可能吗?

这里的code,我正在尝试使用,但它似乎并没有被工作作为ecpected。重定向匹配的文件扩展名,并允许被访问,但 sitemap.html 文件中的 /包括/ 目录,我想是弗罗马用户的角度允许访问,无论什么文件都在似乎仍然被重定向到sitemap.html文件的实际目录。

Here's the code that I'm trying to use but it doesn't appear to be working as ecpected. The redirect matched the file extensions and allows the sitemap.html file to be accessed but the /includes/ directory that I want to be allowed access to froma user perspective regardless of what files are in the actual directory still appears to be redirecting to the sitemap.html file.

RewriteEngine On
RewriteCond %{REQUEST_URI} !(.(gif|jpg|css|js|ico|png)$|^/includes$|^/sitemap.html$)
RewriteRule ^(.*)$ /sitemap.html [R=301,L]

任何帮助将是很大的AP preciated。

Any help would be greatly appreciated.

推荐答案

试试这个:

RewriteCond %{REQUEST_URI} !.(gif|jpg|css|js|ico|png)$ [NC]
RewriteCond %{REQUEST_URI} !^/(sitemap.html|includes(/.*|))$ [NC]
RewriteRule ^ /sitemap.html [R=301,L]

当然两者的RewriteCond线可组合成1,但我会建议保持它的2个独立的,因为这是要排除在未来增加新的扩展和新的目录更容易阅读和方便的情况下维护。

Sure both RewriteCond lines can be combined into 1 but I would suggest keeping it 2 separate as this is easier to read and easy to maintain in case you want to add new extensions or new directories for exclusion in future.

阅读全文

相关推荐

最新文章