2

I have to redirect all my asp page to new website developed in PHP.

I had my asp page as,
abc.asp?id=82

Which need to be redirected to
siteurl/index.php/abc

Can any one help me with this in HTAccess?

I have tried with,
Redirect 301 /abc.asp?id=82 siteurl/index.php/abc

rewriterule ^/abc.asp?id=82$ siteurl/index.php/abc[R=301,L]

But this is not working and giving me a 404 error.

3
  • You have abc.asp in your rewrite rule while as per your example you want to redirect content.asp ? Commented Apr 24, 2013 at 9:48
  • Do you want to redirect content.asp page to new site url ? Commented Apr 24, 2013 at 9:50
  • it was my mistake .its not content.asp page which i need to redirect.the needed page is abc.asp?id=82 Commented Apr 24, 2013 at 9:55

3 Answers 3

2

You can't match against the query string in either a Redirect or RewriteRule. It's not very clear what the scope you're trying to accomplish here. Is the id=82 important? Does abc mean "anything that's just letters"? Is siteurl a directory or a domain name? If it's strictly what you've attempted, then this is strictly how it'll work:

RewriteEngine On
RewriteCond %{QUERY_STRING} ^id=82($|&)
RewriteRule ^/?abc.asp$ siteurl/index.php/abc? [L,R=301]
Sign up to request clarification or add additional context in comments.

3 Comments

Yes we have to strictly follow this as our old site was in asp and we don't want to send our user to "Page not found" page.
Above is working for me but it is attaching querysting as it was given in the RewriteCond %{QUERY_STRING} ^id=82($|&).Does this has any other way?
@ArpiPatel Sorry, left out the ? at the end of the rule
1

You're making 2 main mistakes:

  1. Rewrite rule matches only URI part and doesn't match query string
  2. Rewrite rule in .htaccess doesn't match leading slash.

Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteCond %{QUERY_STRING} ^id=82(&|$) [NC]
RewriteRule ^(abc)\.asp$ http://domain.com/index.php/$1 [R=302,L,NC]

Once you verify it to be working replace 302 (Temporary Redirect) with 301 (Permanent Redirect)

Comments

0

Just use

RewriteRule ^abc.asp$ siteurl/index.php/abc [R=301,QSA,L]

That should do the job.. Using the QSA flag will forward any GET paramater too, if that's what you meant with the title.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.