I have a website which was originally built using classic ASP. About a year ago it was rewritten in PHP. This caused file extensions to change and some pages were moved to new locations within the website. Naturally we made 301 redirects from the old URLs to the new URLs so their users and search engines could find their new locations. This works fine.
We also built them a tool that allows the site owner to create their own tiny URLs that will redirect to a page with Google Analytics campaign tracking variables included in the URL so they can track the campaign and see how it performs.
The issue I have is the campaign tracking rules conflicts with the 301 redirects and prevents the redirects from working at all.
Here is the campaign tracking code:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /tracking.php?$1 [R=301,L]
As you can see it checks to see if a file exists and if it doesn't it redirects to a tracking script (tracking.php) which then takes the tracking code and redirects to the proper URL with the Google Analytics campaign code in the query string.
That code causes rules like this to fail:
redirect 301 /about.asp /about.php
redirect 301 /capabilities.asp /capabilities.php
redirect 301 /capacitors.asp /capacitors.php
It makes sense that this doesn't work together as the tracking rules say, "if a file isn't found redirect to tracking.php". What I need is for the 301 redirects to run first, and if none of them match, then redirect to the tracking script. Placing the tracking rules below the 301 redirects does not change the results.
Can this be done via .htaccess? Or will I need to modify the tracking script so that if a campaign is not found it checks to see if the campaign ID is actually an old page that needs to be redirected and then do the 301 redirect from there?