Forum Moderators: phranque
For this I have added the rule in htaccess file
Redirect 301 /modules/page1.php?category=1 [domain.com...]
But it is not working. I think the problem arises because of '?' and '=' characters. If anyone knows how to escape these characters and make the redirect work plz suggest.
RewriteEngine On
RewriteCond %{QUERY_STRING} ^category=1$
RewriteRule ^modules/page1\.php$ [domain.com...] [R=301,L]
However if you want to do mass redirection based on the category parameter, you can do:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^category=([0-9]+)$
RewriteRule ^modules/page1\.php$ [domain.com...] [R=301,L]
These are just rough examples, your situation might be slightly different (you did not mentioned from where pagename.html comes, does it change or not in any case,...), but you should be able to adapt it to your needs. For more information see the mod_rewrite documentation [httpd.apache.org] and the URL Rewriting Guide [httpd.apache.org], both from the Apache documentation.
according to your suggestion I have tried it, but it is not working.
In our htaccess file we rewrite all .html to .php by
RewriteRule ^(.*).html$ $1.php [NC]
RewriteRule ^(.*).xml$ $1.php [NC]
Is there any problem because of these rules?
You seem to have changed your links that far that you can not easily change them with mod_rewrite, you would need to use a RewriteMap [httpd.apache.org], but unless you have access to the server configuration, you can't do that.
If your old url does not contain more information than the identifier of the article or category, but in the new links, the name of the link is also there, then you may need to find an another way. Like handling the link change with your own (php) script, which is capable of making database queries, and finding the missing information.
Why the rules did not work for you, I don't know, you would need to tell which url you really tried, and where's the actual file (or what other rewriting rules affect that) on the file system.