0

I am using the following in my .htaccess file to remove index.php:

<IfModule mod_rewrite.c>
RewriteEngine On
# Removes index.php
RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]

# Redirect non-www to www
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L] 
</IfModule>

I need to redirect an old page to a new, existing page but I am getting strange results.

I added the following to the .htaccess:

Redirect 301 /Payment.aspx /clients/login

But the url it redirects to looks like this:

http://www.myurl.com/clients/login?/Payment.aspx

It is adding that extra query string to the end of the URL.

Is there any way around this?

1 Answer 1

0

When people hit your /Payment.aspx path, will they sometimes be linked with a query string?

Also, for best results, try this:

RedirectMatch 301 (?i)^/Payment.aspx https://www.full-domain.com/clients/login

... which I'm 99% sure won't work if you do have query strings when you hit that payment path.

What you really want is a RewriteRule and then just drop query strings.

RewriteRule ^payment\.aspx$ /clients/login? [L,R=301,NC]

The trailing question mark should strip off any original query strings. The flags set it for 301, Last, and NoCase (ignore upper vs lower case payment.aspx variations. If the question mark doesn't do it, add a QSD flag (query string drop). That flag (QSD), I think, was introduced somewhat recently in mod_rewrite, so it may not be available in older versions and less maintenanced servers.

Also, this is dangerously close to not being EE related, but since you posted your EE related rewrites, I figured it was just close enough :p

5
  • There will never be query strings. And thanks for the help for my close enough question! :)
    – mediapimp
    Dec 22, 2015 at 23:55
  • Actually, none of those worked for me. The RedirectMatch gave me the same results. The RewriteRule as written gave me a page not found error and adding QSD gave me a server error.
    – mediapimp
    Dec 23, 2015 at 0:04
  • LULZ, sorry I failed. That was off the top of my head; I'll jump on a test server and see if I can test an actual result.
    – jrothafer
    Dec 23, 2015 at 0:10
  • What was your resulting URL from the RewriteRule ? I tested the exact code I dropped, and it redirected me from http://test.server.ip.num/payment.aspx to http://test.server.ip.num/clients/login. NOTE; I put the RewriteRule before the EE rewrite rules, just after RewriteEngine On
    – jrothafer
    Dec 23, 2015 at 0:18
  • I think it must have been the order. I moved it to the top and it works fine now. Thank you!!!
    – mediapimp
    Dec 23, 2015 at 0:22

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.