How to redirect URLs based on query string?

前端 未结 2 393
有刺的猬
有刺的猬 2020-11-27 07:03

I successfully mass migrated a Wordpress site to Drupal. Unfortunately in Wordpress, the content URL\'s were something like www.example.org/?p=123. My domain is still the

相关标签:
2条回答
  • 2020-11-27 07:19

    neither Redirect nor RedirectMatch allow you to specify a query string for the redirect source. [Source]

    You have to use mod-rewrite for redirecting based on query string:

    RewriteCond %{QUERY_STRING}  ^p=375$
    RewriteRule (.*)  http://www.example.org/content/MyNewPage?  [R=301,L]
    
    0 讨论(0)
  • 2020-11-27 07:24

    You may consider use ModRewrite in your htaccess

    <IfModule mod_rewrite.c>
    
    RewriteEngine On
    
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    
    RewriteCond %{QUERY_STRING}     ^p=345$    [NC]
    RewriteRule index.php content/MyNewPage [NC,L,R=301]
    
    </IfModule>
    

    And you also may want to pass the old page id to the new URL concatenated (or maybe by QS?):

    <IfModule mod_rewrite.c>
    
    RewriteEngine On
    
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    
    RewriteCond %{QUERY_STRING}     ^p=(.*)$    [NC]
    RewriteRule index.php content/MyNewPage-%1 [NC,L,R=301]
    
    </IfModule>
    
    0 讨论(0)
提交回复
热议问题