Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
716 views
in Technique[技术] by (71.8m points)

.htaccess - Htaccess RewriteRule

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.

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]

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.

How to fix this?

Thanks! Wouter0100

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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]

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...