Forum Moderators: phranque

Message Too Old, No Replies

problem regarding 301 permanent ridirect

problem regarding 301 permanent ridirect because of '=' and '?'

         

Dss_dev

2:04 pm on Mar 5, 2008 (gmt 0)

10+ Year Member



Need some help regarding redirecting a url using 301 redirect.
The old url is like that
[domain.com...]
and I want to redirect it to the url
[domain.com...]

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.

gergoe

6:04 pm on Mar 5, 2008 (gmt 0)

10+ Year Member



The Redirect directive does not work with the query string, for this you will need to use mod_rewrite. To do the same thing with mod_rewrite:

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.

Dss_dev

6:20 am on Mar 6, 2008 (gmt 0)

10+ Year Member



Thank you for your replay. The main thing is that we are upgrading our site into new version. In old version url of an article was [domain.com...]
but in new version this url changed to
[domain.com...]

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?

gergoe

11:23 am on Mar 6, 2008 (gmt 0)

10+ Year Member



First you mention categories, and now articles? Which one then? :-)

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.