Trying to get [a-z] part of redirect to work in .htaccess

foolstack asked
wordpress .htaccess
via

Here’s my current .htaccess file contents:

# 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

# BEGIN wtwp_cache
# END wtwp_cache
# BEGIN wtwp_security
# END wtwp_security

Redirect 301 /2016/03/26/alex-bayne-2-ohio-state/ http://website.com/softball/alex-bayne-2-ohio-state/ #REDIRECT **WORKS** FINE
Redirect 301 /tag/southpaw-throws-left/ http://website.com/softball-tag/southpaw-throws-left/ #REDIRECT **WORKS** FINE

RewriteRule ^/tag/([A-Za-z0-9-]+)/?$ /softball-tag/$1 [NC,R=301,L] #REDIRECT **DOESN'T WORK**

What I’m trying to do is redirect /tag/ANYTHING-AFTER to /softball-tag/ANYTHING-AFTER and the URL keeps all same content except replaces /tag/ with /softball-tag/

thanks!


Answer
via

Here’s what you want, including QSA so the ?query is preserved too.

RewriteRule ^tag(/.*|$) /softball-tag$1 [NC,QSA,R=301,L]

Demo: https://regex101.com/r/ftxDit/1

Share This
Posted in: