Forum Moderators: phranque
I am now redoing an old site, and everything is tested and ready with exception of the rewrite rule to redirect SE requests for the old dynamic URLs to the new static URLs. Saw several threads about it, including Jim’s, but cannot get that one to work.
We have only a handful of pages without clear links between dynamic and static URL. The internal static-dynamic rewrite rules just mention each page individual, I try to do the same here with the dynamic-static rules:
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /\?act=5\ HTTP/
RewriteRule ^\?act=5$ http://www.example.org/nice-url? [R=301,L]
Also not working:
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\?act=5\ HTTP/
Or
RewriteCond %{THE_REQUEST} ^\?act=5\ HTTP/
It should be very simple but what am I doing wrong here?
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /\?act=5\ HTTP/
RewriteRule ^$ http://www.example.org/nice-url? [R=301,L]
Just a last question (I hope):
Almost all links will be to www.example.org/? (homepage) or www.example.org/?act=xx (other pages). That is now taken care of by this last rule.
However, when directly entering www.example.org/index.php (home page) and www.example.org/index.php?act=xx in the browser they still show the old dynamic URL (no redirects). I don't think many people -if any- will have links using those URLs, but is it normal to externally redirect them also as precaution or just leave it as I have it now (only the \? without index\.php\? variations) to keep your htaccess as small as possible.
More specifically, does an SE register or store the home page as www.example.org and automatically get the index.php or actually store it as www.example.org/index.php? If the later, that URL might need its own redirect as well probably?
Thanks again
Robo
RewriteCond %{QUERY_STRING} (.*)
RewriteRule ^index\.php$ http://www.example.org/?%1 [R=301,L]
Note that in the case where the query string is blank, the trailing "?" on the replacement URL will be discarded -- as it should be.
Jim
Order of rules in .htaccess:
- first ALL the internal rewrites from SEF url to dynamic. All rules end with [L]
- then all the external redirects for SEs still using the normal dynamic URLS, ending with [R=301,L]
- finally your last suggestion for getting the old .../index.php? links redirected as well, also ending with [R=301,L]
In Firefox, the URL changed from example.org/index.php?act=12 to the SEF url (example.org/nice-url), but did not load the page. Firefox gives an error message "Firefox has detected that the server is redirecting the request for this address in a way that will never complete"
Besides, entering a SEF URL now does not result in an internal rewrite anymore but ends as well with the same error message.
Changing it to ^ (.*) makes that the URL changes from .../index.php?act=12 to …/?act=12, but still the page does not load, the SEF does not work either, and both still give the same error message?
It is strange that the SEF URLs also stop work. Should not the internal rewrite rule with its ending in [L] stop the process before ever getting to the final rule?
The rule must only be invoked for direct client requests for "index.php", and not as the result of an internal rewrite. So we must examine %{THE_REQUEST} -- The original request header as received from the client:
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php(\?([^\ ]*))?\ HTTP/
RewriteRule ^index\.php$ http://www.example.org/?%2 [R=301,L]
In addition, if an external redirect is invoked, then the client will issue an entirely-new HTTP request, restarting *all* server-side directive processing.
Jim
Actually, the thing not working made me think hard on what it was trying to do and why it should or should not work, which is better than just blindly copying a solution. Thought I start getting close to understanding, but clearly not close enough yet.
All double-checked and all rules are working fine.
Thanks again
Robo
For example:
For our news I have displayarticle(.*).html for all articles, the dynamic URL for that is index.php?name=News&file=article&sid=$1
Which I redirect like this and worked OK:
RewriteRule ^displayarticle([0-9]+)\.html$ index.php?name=News&file=article&sid=$1 [L,NC,NS]
Now the problem I am having is in Google WMT telling me I have duplicate Titles, I can understand why, it's because when you paste an URL from my dynamic URLs on the browser it still takes you to the article, example mysite.com/index.php?name=News&file=article&sid=37788
The site suffered a penalty for three years now and I think is because we changed all dynamic URLs to SEF URLs when the old dynamic URLs were the ones which held most of the PR and had all backlinks, the site was PR8 going on PR9 and a leader in its field to a mere PR6 now with 90% of traffic wiped out :( but I am not bitter!
I wanted to 301 redirect index.php?name=News&file=article&sid=37788 to displayarticle37788.html for anyone pasting it on the browser or clicking on it on other sites, which will in time 301 redirect all old bookmarked and backlinks to the current URL.
I tried the above suggestion, I am not having any luck, could someone give me a pointer?
Jim