nooblag
nooblag

Reputation: 349

Pattern matching for htaccess rewrite rules involving one folder to another

I need some quick help cleaning up the following rules for htaccess file, as the list is getting quite long.

This has occurred after a site move which makes author pages that previously came from /browse/author/NAME-HERE now sit at /by/NAME-HERE.

Surely there's a way to pattern match these or something?

Redirect /browse/author/some-person /by/some-person
Redirect /browse/author/another-person /by/another-person
Redirect /browse/author/some-other-person /by/some-other-person
Redirect /browse/author/yet-more /by/yet-more
Redirect /browse/author/ /

I'd like to keep the /browse/author/ redirect to the root though, if possible...

Many thanks for any help!

Upvotes: 2

Views: 1581

Answers (1)

anubhava
anubhava

Reputation: 785156

This is definitely possible with mod_rewrite.

Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteRule ^/?browse/author/(.*) /by/$1 [L,R=301,NC]

Upvotes: 2

Related Questions