Newbie question sorry!

I have read the documentation on apache.org and I understand the basics, but the way rules interact with each other is confusing me!

I have the following .htaccess file, it checks whether a file or directory exists and ignores it if it does (because the page can load directly).

If the file does not exist it takes the last part of the URL and sends it to the redirect.php page of the CMS which serves up the page with a clean url e.g. /mywebsite.com/clean-url

I'm trying to rewrite some old CMS pages that no longer exist, but I'm not sure how the rules are interacting with each other - the best I can come up with is:

/mywebsite.com/old-url to /mywebsite.com/redirect.php?code=new-url

instead of:

/mywebsite.com/old-url to /mywebsite.com/new-url

I'd be really grateful for any advice based on my current .htaccess as below:

RewriteEngine on
RewriteBase /

# CHECK THE DIRECTORY OR FILE EXISTS
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
 
# IF YES DO NOTHING
RewriteRule ^.*$ - [L]

# OTHERWISE REDIRECT AND GET THE ID FROM LOAD PAGE
RewriteRule ([^/]+) /templates/redirect.php?code=$1

# REDIRECT OTHER PAGES
RewriteRule /old-url /new-url
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.