d.jordan
d.jordan

Reputation: 63

.htaccess Redirect Rewrite Rule

I'm struggling with some redirects on the redesign of a website. The old one got several urls like this:

http://www.example.com/sitegroup/pages/GA/GA_Be.shtml

And I want to redirect this to:

http://www.example.com/sitegroup/garten-und-landschaftsbau/#gartenforum-ideengarten

I tried it with the following rewriterule:

RewriteRule ^/?pagesGA/GA_Be.shtml$ http://www.example.com/sitegroup/garten-und-landschaftsbau/#gartenforum-ideengarten$1 [R=301,L,NE]

But I just can't get it working.. I'm really new to .htaccess rewriterules.

Also some of the old pages got links like this:

http://www.example.com/sitegroup/pages/GA/GA_Be.shtml?navid=15

But the ?navid=15 isn't doing something(just highlighting the menulink) so I thought just redirecting the GA_BE.shtml should be enough. Am I correct?

Here is the complete .htaccess:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /sitegroup/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /sitegroup/index.php [L]
</IfModule>

# END WordPress

RewriteRule ^/?pagesGA/GA_Be.shtml$ http://www.example.com/sitegroup/garten-und-landschaftsbau/#gartenforum-ideengarten$1 [R=301,L,NE]

Thanks in advance!

Upvotes: 2

Views: 105

Answers (1)

Florian Lemaitre
Florian Lemaitre

Reputation: 5748

You should put your RewriteRule before Wordpress Dispatcher:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /sitegroup/
    RewriteRule ^pages/GA/GA_Be\.shtml$ http://www.example.com/sitegroup/garten-und-landschaftsbau/#gartenforum-ideengarten [R=301,L,NE]
    RewriteRule ^pages/GA/GA_Bg\.shtml$ http://www.example.com/sitegroup/garten-und-landschaftsbau/#gartenplanung-landsc‌​haftsplanung [R=301,L,NE]
    RewriteRule ^pages/GA/GA_En\.shtml$ http://www.example.com/sitegroup/garten-und-landschaftsbau/#erdsondenbohrung-erd‌​waerme [R=301,L,NE]
</IfModule>

# BEGIN WordPress
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /sitegroup/
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /sitegroup/index.php [L]
</IfModule>
# END WordPress

Otherwise the request will first be handled by the Dispatcher and never reach your rule.

Upvotes: 2

Related Questions