Search code examples
.htaccessmod-rewritehttp-status-code-301http-redirect

Redirecting causes url to change and won't redirect


I've made a redirect in a htaccess file:

Redirect 301 /example.com/oldAddress http://www.example.com/newAddress.php
ErrorDocument 404 /index.php

But it generates this url:

http://www.example.com/newAddress.php?redirect=1

so it causes a 404 error. How can I make it work?


Solution

  • put this code in your DOCUMENT_ROOT/.htaccess file:

    RewriteEngine On
    
    RewriteRule ^oldAddress http://www.example.com/newAddress.php? [L,NC,R=301]
    

    ? in the end will target any existing query string.