简体   繁体   中英

Why does my HTACCESS don't work with more than one RewriteRule in PHP?

i've a little problem with multiple RewriteRules in PHP.

This is my htaccess:

DirectoryIndex start.php

RewriteEngine on 

RewriteRule insert          insert_kunde.php
RewriteRule insert2         insert_kunde_2.php

If i call http://127.0.0.1/Adressen-REST/insert it works fine and redirect me to insert_kunde.php .

But if i call http://127.0.0.1/Adressen-REST/insert2 , i will be redirected to insert_kunde.php, not to insert_kunde_2.php.

If i comment this line out, it works:

#RewriteRule insert         insert_kunde.php

Does some know why?

You need to be more precise with your patterns:

RewriteEngine on
RewriteRule ^/?Adressen-REST/insert$ /Adressen-REST/insert_kunde.php [END]
RewriteRule ^/?Adressen-REST/insert2$ /Adressen-REST/insert_kunde_2.php [END]

The issue in your example is that the fuzzy pattern insert matches all of /insert , /insert2 , insert_kunde.php and insert_kunde_2.php . So your first rule will always get applied. And will get applied again to an already rewritten request.

You have todo something like this. define internal path too, to tell the server.!

RewriteRule insert          insert_kunde.php
RewriteRule insert2         insert_kunde_2.php

To this :

RewriteCond %{THE_REQUEST} /insert_kunde.php\sHTTP  [NC]
RewriteRule ^ /insert/ [L,R]
RewriteCond %{THE_REQUEST} /insert_kunde_2.php\sHTTP  [NC]
RewriteRule ^ /insert2/ [L,R]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/insert_kunde.php [L]
RewriteRule ^/insert_kunde_2.php [L]

i hope this will work.!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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