Forum Topic: RedirectMatch Not redirecting

Forum: .htaccess Forum : Redirecting • Posted by Mike Simmons • Updated:

Trying to drop /Project/ Custom Post from Divi 2.0 Theme URLs using Page Builder for SEO. Seems like the perfect application for RedirectMatch, but it’s not working. Here’s my best effort thusfar:

<IfModule mod_rewrite.c>
	RewriteEngine On
	RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
	RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
	RedirectMatch 301 ^/project/(.*) http://website.com/$1
</IfModule>

# 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

3 Replies to “RedirectMatch Not redirecting”

Posted by Jeff Starr

Hi Mike,

Although the location is a tiny bit odd, the RedirectMatch that is included looks like it should work. As a test, you might try moving it 1) out of the IfModule/mod_rewrite container, and/or 2) after the WP rules. Lastly, I would double-check the server to make sure that mod_alias is installed (or add IfModule/mod_alias container for the RedirectMatch).

Posted by Mike Simmons •

Jeff,

Thanks for the quick response. The site that I am trying to do this on on hosted at GoDaddy. I have 20 other sites there and haven’t had any problem with the mod_Rewrite module functionality not being turned on. Here’s the latest, taking your advice to pull thing out into a separate <IfModule> block after WP:

# 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 Remove /project/ string in URL
<IfModule mod_rewrite.c>
	RewriteEngine On
	RewriteBase /
	RedirectMatch ^/project/(.*) http://website.com/301$1
</IfModule>
# END Remove /project/ string in URL

I did add the RewriteBase / statement, thinking maybe Apache needs it to know where the root directory is (as in the WP case). Still /project/ is unaffected, appearing, as before, in the URL strings. Anything else you can can think of that might be causing the problem? Thanks again.

Mike

Posted by Jeff Starr

I’m noticing a few things here:

1) RewriteBase does not work with RedirectMatch. The first is a mod_rewrite directive and the other is a mod_alias directive.

2) The IfModule container for the RedirectMatch should be <IfModule mod_alias.c>

3) There is no need to declare RewriteEngine more than once per .htaccess file.

Those things considered, if mod_alias isn’t enabled, I would recommend trying mod_rewrite for the /project/ redirects. For example something like this:

<IfModule mod_rewrite.c>
	RewriteCond %{REQUEST_URI} ^/project/(.*) [NC]
	RewriteRule .* http://example.com/%1 [R=301,L]
</IfModule>