Htaccess RewriteRule [英] Htaccess RewriteRule

查看:155
本文介绍了Htaccess RewriteRule的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在提出此问题后,将Htaccess URLRewrite转到另一个地图
这很好,但现在我想添加一个额外的地图,但是这不行。

After asking this question Htaccess URLRewrite to another map That works great, but now i want to add an extra 'map', but that don't work.

我的.htaccess文件现在:

My .htaccess file now:

ErrorDocument 404 /v2/404.php
ErrorDocument 404 /v2/505.php

RewriteEngine on

RewriteRule ^error/([^/]+)/?$ error.php?id=$1 [L,QSA,NC]

RewriteRule ^email/([^/]+)/?$ email.php?id=$1 [L,QSA,NC]

RewriteRule ^activate/([^/]+)/?$ activate.php?code=$1 [L,QSA,NC]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^werknemer/([^/]+)/?$ werknemer/$1.php [L,QSA,NC]

RewriteRule ^klanten/([^/]+)/?$ klanten/$1.php [L,QSA,NC]

RewriteCond %{REQUEST_FILENAME}.php -f

RewriteRule ^(.*)$ $1.php [L]

总是最后一个工作,现在RewriteRule ^ klanten /不工作,当我做RewriteRule ^ werknemer /之后RewriteRule ^ klanten /,RewriteRule ^ klanten /工作,但RewriteRule ^ werknemer /不。

Always the last wont work, now RewriteRule ^klanten/ don't work, and when i do RewriteRule ^werknemer/ after RewriteRule ^klanten/, RewriteRule ^klanten/ works but RewriteRule ^werknemer/ not.

如何解决这个问题?

谢谢!
Wouter0100

Thanks! Wouter0100

推荐答案

您需要再次复制2个条件。 RewriteCond 仅适用于紧随其后的 RewriteRule ,所以您需要复制条件,如果它们是应用于多个规则:

You need to duplicate the 2 conditions again. RewriteCond's are only applied to the immediately following RewriteRule, so you need to duplicate the conditions if they are to be applied to more than one rule:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^werknemer/([^/]+)/?$ werknemer/$1.php [L,QSA,NC]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^klanten/([^/]+)/?$ klanten/$1.php [L,QSA,NC]

也许您需要最后一条规则:

Maybe you need it for your last rule as well:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^/(.*?)/?$
RewriteCond %{DOCUMENT_ROOT}/%1.php -f
RewriteRule ^ /%1.php [L]

检查是否存在尾部斜线,并在看到是否将 php 添加到结尾之前删除它将生成现有文件。

That checks if a trailing slash exists, and to remove it before seeing if adding the php to the end produces an existing file.

这篇关于Htaccess RewriteRule的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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