Crashy
Crashy

Reputation: 345

Massive links convertion from 302 to 301

I have a WordPress website with different 302 redirects, I would like to change these links from 302 redirects to 301.

I have more or less 160 links so I need to find a massive way to do it. Is it possible to do?

I could use this

# BEGIN 301 Redirects
Redirect 301 /wp/old-page/ http://www.testdomain.com/wp/new-page/
# END 301 Redirects

But in this case, I should convert all the links one by one which is not really quick.

This is my .htaccess file:

# BEGIN WpFastestCache
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Start WPFC Exclude
# End WPFC Exclude
RewriteCond %{HTTP_USER_AGENT} !(facebookexternalhit|WhatsApp|Mediatoolkitbot)
RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{REQUEST_URI} !(\/){2}$
RewriteCond %{REQUEST_URI} \/$
RewriteCond %{QUERY_STRING} !.+
RewriteCond %{HTTP:Cookie} !(comment_author_|wordpress_logged_in|wp_woocommerce_session)
RewriteCond %{HTTP:Profile} !^[a-z0-9\"]+ [NC]
RewriteCond %{DOCUMENT_ROOT}/wp-content/cache/all/$1/index.html -f [or]
RewriteCond /home/abbeyse1/public_html/wp-content/cache/all/$1/index.html -f
RewriteRule ^(.*) "/wp-content/cache/all/$1/index.html" [L]
</IfModule>
<FilesMatch "\.(html|htm)$">
AddDefaultCharset UTF-8
<ifModule mod_headers.c>
FileETag None
Header unset ETag
Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
Header set Pragma "no-cache"
Header set Expires "Mon, 29 Oct 1923 20:30:00 GMT"
</ifModule>
</FilesMatch>
# END WpFastestCache
# BEGIN GzipWpFastestCache
<IfModule mod_deflate.c>
AddType x-font/woff .woff
AddOutputFilterByType DEFLATE image/svg+xml
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE application/x-font-ttf
AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
AddOutputFilterByType DEFLATE font/opentype font/ttf font/eot font/otf
</IfModule>
# END GzipWpFastestCache
# BEGIN LBCWpFastestCache
<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf|x-html|css|xml|js|woff|woff2|ttf|svg|eot)(\.gz)?$">
<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault A0
ExpiresByType image/gif A2592000
ExpiresByType image/png A2592000
ExpiresByType image/jpg A2592000
ExpiresByType image/jpeg A2592000
ExpiresByType image/ico A2592000
ExpiresByType image/svg+xml A2592000
ExpiresByType text/css A2592000
ExpiresByType text/javascript A2592000
ExpiresByType application/javascript A2592000
ExpiresByType application/x-javascript A2592000
</IfModule>
<IfModule mod_headers.c>
Header set Expires "max-age=2592000, public"
Header unset ETag
Header set Connection keep-alive
FileETag None
</IfModule>
</FilesMatch>
# END LBCWpFastestCache
suPHP_ConfigPath /home/abbeyse1/public_html


Options +FollowSymLinks
# 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]
</IfModule>

# END WordPress

Here a list of the first links:

Redirect 301 /seal-manufacturing/rod-piston-bearing-rings/titel-197/ https://abbeyseals.ie/seal-manufacturing/rod-piston-bearing-rings/

Redirect 301 /seal-manufacturing/rotary-seals/dr113-2/ https://abbeyseals.ie/seal-manufacturing/rotary-seals/

Redirect 301 /seal-manufacturing/rod-seals/titel-164/ https://abbeyseals.ie/seal-manufacturing/rod-seals/

Redirect 301 /seal-manufacturing/piston-seals/dk216/ https://abbeyseals.ie/seal-manufacturing/piston-seals/

Redirect 301 /seal-manufacturing/rod-seals/titel-185/ https://abbeyseals.ie/seal-manufacturing/rod-seals/

Redirect 301 /seal-manufacturing/rotary-seals/dr108/ https://abbeyseals.ie/seal-manufacturing/rotary-seals/

Redirect 301 /seal-manufacturing/o-rings-back-rings-gaskets/titel-212/ https://abbeyseals.ie/seal-manufacturing/o-rings-back-rings-gaskets/

Redirect 301 /seal-manufacturing/o-rings-back-rings-gaskets/titel-208/ https://abbeyseals.ie/seal-manufacturing/o-rings-back-rings-gaskets/

Redirect 301 /seal-manufacturing/rotary-seals/dr111/ https://abbeyseals.ie/seal-manufacturing/rotary-seals/

Upvotes: 1

Views: 33

Answers (1)

anubhava
anubhava

Reputation: 785481

Insert this generic rule just above # Start WPFC Exclude line:

RewriteRule ^/?(seal-manufacturing/[\w-]+/)(.+)$ /$1 [L,NE,R=301,NC]

Upvotes: 2

Related Questions