I've been working on a new set of htaccess rewrite rules for a module I am creating. The htaccess file already has some rules for the PHP-based application and those rules are now broken. I am wondering if there is a way to fix this. Here is the code:
# My Module Rules
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/?(.*?)/?$ ./page.php?url=$1 [L]
RewriteCond %{THE_REQUEST} /page\.php\?url=([^\&\ ]+)
RewriteRule ^/?page\.php$ ./%1/? [R=301, L]
</IfModule>
# Application Rules
<IfModule mod_rewrite.c>
RewriteEngine on
# RewriteBase is set to "/" so rules do not need updating if the
# installation directory is relocated. It is imperative that
# there is also a RewriteCond rule later that can effectively get
# the actual value by comparison against the request URI.
#
# If there are _any_ other RewriteBase directives in this file,
# the last entry will take precedence!
RewriteBase /
# Redirect directories to an address with slash
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.+[^/])$ $1/ [R]
# Send all remaining (routable paths) through index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Determine and use the actual base
RewriteCond $0#%{REQUEST_URI} ([^#]*)#(.*)\1$
RewriteRule ^.*$ %2index.php [QSA,L]
</IfModule>
The rules I have above are working for my module URLs:
https://www.example.com/page.php?url=test-page => https://www.example.com/test-page/
However, it's breaking the rewrite rules for the main application, here is an example:
https://www.example.com/admin/setup => 404 Error
I've tried to re-arrange the rules, but then my rewrite doesn't work. I'm also trying to not edit the application's rules because those are standard for people who use it.
I tried to add another conditional that would check to see if the requested URL contains "page.php", but it did not fix the issue. Here was the code I used:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^/?page\.php$
RewriteRule ^/?(.*?)/?$ ./page.php?url=$1 [L]
RewriteCond %{THE_REQUEST} /page\.php\?url=([^\&\ ]+)
RewriteRule ^/?page\.php$ ./%1/? [R=301, L]
</IfModule>
Perhaps something is wrong with the code and I'm hoping someone could point me in the right location. Thank you all!