htaccess 301 redirect rule - .htaccess

Well, I have website with such structure of pages:
domain.com/group-1/page/ and now I need to make htaccess 301 redirect to
domain.com/group-1/{constant}-page/
where {constant} any fixed word (plus minus sign). This rule should not effect any other groups, except group-1
Thank You.

This can be done with mod_rewrite. Put this .htaccess code into the domain's root directory.
RewriteEngine On
RewriteRule ^group-1/page/(.*)$ group-1/constant-page/$1 [L,R=301]

Related

Redirect everything after domain.com/articles.php

So i have this issue, with changing an old site with a new and I need to redirect all the old links. So have this:
domain.com/articles.php?var=1
I basicly want to redirect everything after articles.php to just domain.com, including the /articles.php.
Thank you in advance.
Try adding this to your htaccess file:
RedirectMatch 301 ^/articles\.php$ /
or if you have mod_rewrite rules already in your htaccess file, you need to use mod_rewrite isntead, and add this rule above whatever rules are already there:
RewriteRule ^articles\.php$ / [L,R=301]

htaccess simple Redirect doesn't work with trailing slash

I find a lot of answers to this question (and I have read dozens of them), but they are all about more advanced stuff with patterns and such stuff.
I just need a very simple and basic redirect for static urls.
If I add a trailing slash to the url, the redirect doesn't work and I just can't figure out why.
Example:
RewriteEngine On
Redirect 301 /content https://www.example.com/site/content.html
Redirect 301 /content/ https://www.example.com/site/content.html
https://example.com/content does work, https://example.com/content/ redirects to https://example.com/site/
What is the problem here?
Don't mix mid_rewrite rules with Redirect (mod_alias). Use this rule as very first rule in your root .htaccess:
RewriteEngine On
RewriteRule ^content/?$ https://www.example.com/site/content.html [L,NC,R=302]

Drupal 301 redirects

I am doing a set of 301 redirects in Drupal.
I am using a standard method in the .htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine on
Redirect 301 /user/testimonials http://thesitedomain.com/testimonials
Redirect 301 /user/contact http://thesitedomain.com/contact
</IfModule>
but the return url ends up with "?q=user" and stops it working. eg:
http://thesitedomain.com/about?q=user/about
I am not great at htaccess redirects (obviously) and I am no Drupal expert at all.
Also, if you know of a comprehensive htaccess rewrite resource I would much appreciate reading hat.
You will need to use mod_rewrite instead to strip out existing query string:
RewriteEngine On
RewriteRule ^user/testimonials/?$ http://thesitedomain.com/testimonials? [L,NC,R=301]
RewriteRule ^user/contact/?$ http://thesitedomain.com/contact? [L,NC,R=301]
Take note of trailing ? in target that strips out existing query string.
I can't speak to drupal, but I know you don't need to enclose those redirects in the <IfModule mod_rewrite.c> tags, since they don't use the RewriteEngine, the below would suffice:
Redirect 301 /user/testimonials http://thesitedomain.com/testimonials
Redirect 301 /user/contact http://thesitedomain.com/contact
Are both urls in the same drupal? Or are you moving from a different site?
I mean:
/user/testimonials
http://thesitedomain.com/testimonials
Maybe what you need is to add an url alias for /user/testimonials like /testimonials
See under admin at /admin/config/search/path in drupal 7.
Using .htaccess file is not a good practice, because, in some updates you have to update the .htaccess file too.
You can try GlobalRedirect module to manage your redirects.

301 htaccess redirects with two separate URLs

I have two URLs pointing to the same directory, let's call them www.english.com and www.french.com. My htaccess file has a redirect as follows:
Redirect 301 /one http://www.english.com/#/one
If someone goes to www.english/one they are taken to the revised URL above, but the french URL also redirects to the English. Is there a way to have an if statement of kinds to direct www.french.com/one to www.french.com/#/one while keeping the English redirect in order?
Any help is greatly appreciated
Not with Redirect. But it is possible using mod_rewrite.
RewriteEngine On
RewriteBase /
RewriteRule ^one$ /#/one [R,L,NE]

htaccess Redirect to Child Directory

I'm trying to 301 redirect to a child directory using .htaccess i.e.
Redirect 301 /parent http://example.com/parent/child/
Unfortunately this results in a redirect loop i.e.
/parent/child/child/child/child/etc.
Please could anyone point me in the right direction?
Redirect directive will match and redirect everything that starts with /parent. You need to use RedirectMatch to only redirect this specific folder:
RedirectMatch 301 ^/parent/?$ http://example.com/parent/child/
The same, but using mod_rewrite:
RewriteRule ^parent/?$ http://example.com/parent/child/ [R=301,L]
NOTES:
Place it in .htaccess in website root folder. If placed elsewhere some small tweaking may be required.

Resources