• Hi,

    I’m migrating my website from Shopify to WP. Shopify uses mysite.com/news/article1 and I want to change to mysite.com/blog/article1. The domain name doesn’t change.

    I’d like to know if I’m doing the right thing or not.

    I’d like to add 301 Redirect:

    Redirect 301 /news/page1 /blog/page1
    Redirect 301 /news/page2 /blog/page2
    Redirect 301 /news/page3 /blog/page3
    ...
    ...

    Q1. I added them under <IfModule mod_rewrite.c>. Is it correct?

    Q2. I’d like to change from /news/ to /blog/, is there a better way to do it rather than adding all the posts one by one.

    # BEGIN WordPress
    # The directives (lines) between "BEGIN WordPress" and "END WordPress" are
    # dynamically generated, and should only be modified via WordPress filters.
    # Any changes to the directives between these markers will be overwritten.
    <IfModule mod_expires.c>
    	ExpiresActive On
    	ExpiresByType image/jpg "access plus 24 hours"
    	ExpiresByType image/jpeg "access plus 24 hours"
    	ExpiresByType image/gif "access plus 24 hours"
    	ExpiresByType image/png "access plus 24 hours"
    	ExpiresByType text/css "access plus 24 hours"
    	ExpiresByType application/pdf "access plus 1 week"
    	ExpiresByType text/javascript "access plus 24 hours"
    	ExpiresByType text/html "access plus 5 minutes"
    	ExpiresByType image/x-icon "access plus 1 year"
    	ExpiresDefault "access plus 24 hours"
    </IfModule>
    <ifModule mod_headers.c>
    Header set X-Endurance-Cache-Level "2"
    </ifModule>
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    Redirect 301 /news/page1 /blog/page1
    Redirect 301 /news/page2 /blog/page2
    Redirect 301 /news/page3 /blog/page3
    # more redirect
    ...
    ...
    </IfModule>
    
    # END WordPress
    # php -- BEGIN cPanel-generated handler, do not edit
    # Set the “ea-php74” package as the default “PHP” programming language.
    <IfModule mime_module>
      AddHandler application/x-httpd-ea-php74 .php .php7 .phtml
    </IfModule>
    # php -- END cPanel-generated handler, do not edit
    • This topic was modified 4 years, 6 months ago by shinokada.
    • This topic was modified 4 years, 6 months ago by shinokada.
    • This topic was modified 4 years, 6 months ago by shinokada.
    • This topic was modified 4 years, 6 months ago by shinokada.
Viewing 1 replies (of 1 total)
  • 1. No. You should 301 redirect the directory as follows: RedirectMatch 301 /news(.*) /blog/$1. That one line should be sufficient to redirect all pages from the old to the new directory.

    2. No custom code should be inserted between the #BEGIN WordPress and END WordPress section.

    I suggest you take a backup of your .htaccess file, and then edit as follows:

    #301 Redirect Entire Directory
    RedirectMatch 301 /news(.*) /blog/$1
    
    #Expires Rules
    <IfModule mod_expires.c>
    	ExpiresActive On
    	ExpiresByType image/jpg "access plus 24 hours"
    	ExpiresByType image/jpeg "access plus 24 hours"
    	ExpiresByType image/gif "access plus 24 hours"
    	ExpiresByType image/png "access plus 24 hours"
    	ExpiresByType text/css "access plus 24 hours"
    	ExpiresByType application/pdf "access plus 1 week"
    	ExpiresByType text/javascript "access plus 24 hours"
    	ExpiresByType text/html "access plus 5 minutes"
    	ExpiresByType image/x-icon "access plus 1 year"
    	ExpiresDefault "access plus 24 hours"
    </IfModule>
    
    #File Caching
    <ifModule mod_headers.c>
    Header set X-Endurance-Cache-Level "2"
    </ifModule>
    
    # The directives (lines) between "BEGIN WordPress" and "END WordPress" are
    # dynamically generated, and should only be modified via WordPress filters.
    # Any changes to the directives between these markers will be overwritten.
    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    # END WordPress
    
    # php -- BEGIN cPanel-generated handler, do not edit
    # Set the “ea-php74” package as the default “PHP” programming language.
    <IfModule mime_module>
      AddHandler application/x-httpd-ea-php74 .php .php7 .phtml
    </IfModule>
    # php -- END cPanel-generated handler, do not edit
    
    • This reply was modified 4 years, 6 months ago by barnez. Reason: Fix typo
    • This reply was modified 4 years, 6 months ago by Yui.
Viewing 1 replies (of 1 total)
  • The topic ‘.htaccess for 301 Redirect’ is closed to new replies.