.htaccess Redirect Rewrite Rule - .htaccess

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!

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.

Related

Htaccess causes redirects chain

Recently, we switched from www.example.deto www.example.com/de. Unfortunately some minor and bigger issue occurred with the .htaccess.
Issue
Redirect chain
www.example.de/path redirects to www.example.com/de/path an then to www.example.com/de/path/
How do I remove the unecessary redirect?
Every blog article gets redirected to http and then to https.
https://www.example.de/blog/article redirects to http://example.com/blog/article/ then to https://example.com/blog/article/ and finally to https://example.com/de/blog/article/
The redirect to http only occurs for the blog. The rest off the website doesnt redirect to http.
It seems to me that the htaccess is ignored by requests to the blog. I don`t know what I did wrong!
htaccess www.example.de:
SetEnv PHPRC /home/customer/www/example.de/public_html/php.ini
RewriteEngine on
RewriteRule ^(.*)$ https://www.example.com/de/$1 [R=301,L]
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
htaccess www.example.com/de:
SetEnv PHPRC /home/customer/www/example.com/public_html/php.ini
# BEGIN rlrssslReallySimpleSSL rsssl_version[5.1.0]
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{REQUEST_URI} !^/\.well-known/acme-challenge/
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Possible Solution
Can I add this to solve the Issue with the trailing slash?
RewriteCond %{REQUEST_URI} /(.+)/$
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ https://www.example.com/%1 [R=301,L]

301 permanent redirect not working (WordPress)

I'm trying to redirect all requests to a preview site to a different site. I'm not sure why this is not working. I'm not being redirected when I click the link.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} !^site.preview.com$ [NC]
RewriteRule (.*) newsite.com/$1 [L,R=301]
</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
Answer is to remove the ! in the RewriteCond as this says only rewrite it if the the url is not equal to site.preview.com but I want it to redirect if that url is entered.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^site.preview.com$ [NC]
RewriteRule (.*) newsite.com/$1 [L,R=301]
</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

Rewrite in htaccess not working

I have a page locally that is /shop but I want it to redirect to /shop/designs
I tried to do it with .htaccess but nothing seems to be working.
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^/shop/.*$ /shop/designs/ [R=301,L]
# 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
Any ideas where I am going wrong?
You were almost there, but in htaccess, you cannot use / at the beginning of the path regex.
Change your rule like so:
RewriteEngine On
RewriteRule ^shop$ shop/designs [R=301,L]

i want 301 redirection to multiple pages

i want to change urls of my website, but there many pages, so i cant change them manually.
so i need to change it from htaccess file.
i want to change the below url
http://demos.beusoft.com/ccjk/resource/arabic-translation-services/
with the
http://demos.beusoft.com/ccjk/arabic-translation-services/
i am using wordpress.
this is whole code ....
# BEGIN WordPress
RewriteEngine On
RewriteRule ^ccjk/resource/([^/]+)/$ demos.beusoft.com/ccjk/$1 [L,R=301]
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /ccjk/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /ccjk/index.php [L]
</IfModule>
# END WordPress
please help, how to rewrite the url from the htaccess file.
Try this:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /ccjk/
RewriteRule ^resource/([^/]+)/$ http://demos.beusoft.com/ccjk/$1/ [L,R=302]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /ccjk/index.php [L]
</IfModule>
# END WordPress

.htaccess but only from GET variable

I am using wordpress and need to redirect wp-login?action=register to /registration/ page,
first i did
Redirect /wp-login.php http://www.class-world.com/register/
but then it also keeps redirecting logout wp-login.php?action=logout so cant logout at all.
My question is how to only redirect action=register, instead of whole wp-login.php
I tried with following:
RewriteRule ^/wp-login.php\?action=register$ /register/
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteRule ^/wp-login.php\?action=register$ /register/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
but no luck
Try this code :
RewriteEngine On
RewriteCond %{QUERY_STRING} ^action=register
RewriteRule ^wp-login\.php$ /register/ [R=301]

Resources