We are currently in the process of doing two things:
Changing the domain name on our site to a new one
Making all URLs search engine friendly
On the old domain - all links were of the type “index.php?variable=x&variable2=y”.
We now need to forward those to the search engine friendly URLs. That is not a major problem - what we do is:
RewriteRule ^index\.php$ /redirect.php [QSA,L]
and redirect.php then takes care of creating the new URLs - and then does a 301 redirect.
But - some of the URLs - particularly from incoming links are of the type: http://domain.com/?variable=x&variable2=y, i.e. without any filename (index.php for instance). Is it possible to “catch” these with .htaccess - i.e. send these requests to redirect.php as well ?
Unfortunately I discovered it had a somewhat less wanted side effect - when you type in http://domain.com (with or without trailing slash) the rule is applied as well.
Is there any way to avoid this behaviour ?
By the way Dan - I noticed we both have been around since August 2000 - almost 10 years. You have made slightly more posts than me though
There is no such thing as a domain without a trailing slash. All request URIs begin with a slash. When you don’t type it the browser is adding it for you.
So what is it that you really want to differentiate? What must the URL contain for you to want it redirected?
What I want is for that to be sent to http://newdomain.com/redirect.php - and then 301 redirected with a search engine friendly URL.
This works fine for all old URLs that contained index.php, page.php etc - but not for links that started with /?..
Your first suggestion worked - but unfortunately the main URL would also be sent to redirect.php - meaning when I type in http://newdomain.com/ it wouldn’t load the page as usual but be sent to /redirect.php. This I want to avoid.
Yes - all have the same variable name - so THIS is a working solution. Thanks a LOT. All rewrite rules work as expected now - and even http://newdomain.com.