Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.htaccess overwrite another rule to other page

I have the following rewriterules in my .htaccess file:

RewriteRule ^page_edit_(.*) page_edit.php?page=$1
RewriteRule ^page page.php

If I go to /page_edit_12, for example, I see the content of page.php. But I want to see page_edit.php?page=12.

With the following rules, it gives the correct parameter. So if I go with this rules to /page_edit_12, I see the content of page.php?edit=true&page=12

RewriteRule ^page_edit_(.*) page.php?edit=true&page=$1
RewriteRule ^page page.php

Why I can't break the URL so it can reach a another file, also if a match with another URl is found (/page in /page_edit_12)?

like image 445
LittleStack Avatar asked Nov 26 '25 05:11

LittleStack


2 Answers

Your regex pattern for the second rule matches "/page_edit.php" and rewrites it to /page.php,add a $ at the end of the pattern to restrict it to match /page only.

RewriteRule ^page_edit_(.*) page_edit.php?page=$1 [NC,L]
  RewriteRule ^page/?$ page.php [L]
like image 145
Amit Verma Avatar answered Nov 28 '25 20:11

Amit Verma


You should add the [L] - Last - Flag to your first line, so it will end the process in .htacces:

RewriteRule ^page_edit_(.*) page_edit.php?page=$1 [L]
like image 32
Wolfgang Blessen Avatar answered Nov 28 '25 20:11

Wolfgang Blessen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!