sc2015
sc2015

Reputation: 141

301 redirect with special characters .htaccess

I have a WordPress website and I need to redirect hundreds of URLs to the homepage. My .htaccess looks like this currently...

# BEGIN WordPress

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} \s/+index\.php[?/\s] [NC]
RewriteRule ^ /? [L,R=301]
RewriteCond %{QUERY_STRING} ^(?:page|mact)= [NC]
RewriteRule !^wp-admin/ /? [L,R=301,NC]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

The rewrites are working for how I need it to work which is redirect any links that contain page or mact on the frontend only (not backend WP). The only issue I have is with my category pages which look like this...

www.domain.com/category/general/page/3/?page=page

These category pages redirect to the homepage which I don't want so I need to exclude these types of URLs that contain 'category' from redirecting to the homepage.

Thanks.

Upvotes: 0

Views: 298

Answers (1)

anubhava
anubhava

Reputation: 785531

Change your 2nd rule to this:

RewriteCond %{QUERY_STRING} ^(?:page|mact)= [NC]
RewriteCond %{THE_REQUEST} !/(?:wp-admin|category)/ [NC]
RewriteRule ^ /? [L,R=301,NC]

This will exclude /category/... URLs from this redirect.

Make sure to use a new browser for testing.

Upvotes: 0

Related Questions