简体   繁体   English

网站根目录中htaccess的RewriteRule

[英]RewriteRule for htaccess in root of site

I want to rewrite all URLs to a certain file (/blog/post.php) within certain folders (/blog) except a couple of files (/blog/post.php of course and the root of the directory /blog/index.php or /blog/). 我想将所有URL重写为某些文件夹(/ blog)中的某个文件(/blog/post.php),除了几个文件(当然是/blog/post.php以及目录/ blog / index的根目录)。 php或/ blog /)。 I therefore have this: 因此,我有这个:

RewriteRule ^blog/index.php - [L]

RewriteRule ^blog/post.php - [L]

RewriteRule ^blog/(.*) /blog/post.php [L,QSA]

Where the intended result is that all URLs except index.php and post.php get rewritten to post.php The problem is if I put this in the .htaccess in the site root, when you type just website.com/blog/ it rewrites to page to post.php whereas website.com/blog/index.php doesn't. 如果预期的结果是除index.php和post.php之外的所有URL都被重写为post.php,问题是如果我仅在键入website.com/blog/时将其放在网站根目录的.htaccess中,它将被重写到post.php页面,而website.com/blog/index.php没有。 If I put the same code in the .htaccess file in the blog folder (but without the word blog in each line) it works as expected/wanted. 如果我将相同的代码放在Blog文件夹的.htaccess文件中(但每行中都没有blog),则它会按预期/期望的方式工作。

I'm very sorry for another RewriteRule question but its a specific example/problem I've not been able to find and I would be very grateful if anyone had any tips. 对于另一个RewriteRule问题,我感到非常抱歉,但是我无法找到它的特定示例/问题,如果有人有任何建议,我将不胜感激。

Have your single rule like this: 有一个这样的规则:

RewriteCond %{REQUEST_URI} !/blog/(index|post)\.php$ [NC]
RewriteRule ^blog/(.+)$ /blog/post.php [L]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM