skip to Main Content

I have an old webseite made with php and all URLs have the same schema

domain.de/index.php?<sitename>

The first URL parameter is the sitename.

Now I want to redirect some of those URLs, how would a correct redirection look like that redirects only one of these pages and not all of them

Thanks in advance.

I tried this:

Redirect 301 /index.php?impressum /impressum

Example:

Old URL: /index.php?oldurl
New URL: /newurlWithCompletlyDifferentURLName

Update:

# BEGIN WordPress
# Die Anweisungen (Zeilen) zwischen „BEGIN WordPress“ und „END WordPress“ sind
# dynamisch generiert und sollten nur über WordPress-Filter geändert werden.
# Alle Änderungen an den Anweisungen zwischen diesen Markierungen werden überschrieben.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

RewriteCond %{THE_REQUEST} s/+index.php?impressum1s [NC]
RewriteRule ^ /impressum? [R=301,L]

Update
enter image description here

2

Answers


  1. Full .htaccess:

    # BEGIN WordPress
    # Die Anweisungen (Zeilen) zwischen „BEGIN WordPress“ und „END WordPress“ sind
    # dynamisch generiert und sollten nur über WordPress-Filter geändert werden.
    # Alle Änderungen an den Anweisungen zwischen diesen Markierungen werden überschrieben.
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    
    RewriteCond %{THE_REQUEST} s/+index.php?impressum1s [NC]
    RewriteRule ^ /impressum? [R=301,L]
    
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
    
    RewriteRule ^index.php$ - [L]
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    # END WordPress
    

    Earlier Answer:

    This may work for you in your site root .htaccess:

    RewriteEngine On
    
    # all rules that have different redirect URL
    RewriteCond %{THE_REQUEST} s/+index.php?oldUrl1s [NC]
    RewriteRule ^ /newurl1? [R=301,L]
    
    RewriteCond %{THE_REQUEST} s/+index.php?oldUrl2s [NC]
    RewriteRule ^ /newurl2? [R=301,L]
    
    # a generic rule that will redirect /index.php?foobar to /foobar
    RewriteCond %{THE_REQUEST} s/+index.php?(S+)s [NC]
    RewriteRule ^ /%1? [R=301,L]
    

    Please understand that Redirect directive doesn’t support regex and it just matched starting URI. It cannot match query string.

    Login or Signup to reply.
  2. Could you please try following, written and tested with shown samples. Please make sure you clear your browser cache before testing your URLs.

    RewriteEngine ON
    RewriteCond %{QUERY_STRING} !^$
    RewriteRule ^index.php/? /%{QUERY_STRING}? [R=301,NC,L] 
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search