Deepak Visani
Deepak Visani

Reputation: 51

How to redirect url via .htaccess

I want to redirect via .htaccess

https://www.example.co/en/brand/Abc to https://www.example.co/en/brand/abc

I have tried

RewriteRule ^https://www.example.co/en/brand/Abc https://www.example.co/en/brand/abc [R=301,L]

Upvotes: 0

Views: 47

Answers (2)

Bo Reth
Bo Reth

Reputation: 59

You may try something like this:

Options +FollowSymlinks -MultiViews
RewriteEngine On
# Don't want loops
RewriteCond %{REQUEST_URI} !/abc 
RewriteCond %{REQUEST_URI} /Abc 
RewriteRule . https://www.example.co/en/brand/abc [R=301,L]

URL are usually case-sensitive. Check this document, while domain names are not. Therefore "abc" and "Abc" are not the same and that's what the question is about. I think.

Upvotes: 2

MrWhite
MrWhite

Reputation: 45829

The RewriteRule pattern (1st argument to the RewriteRule directive) matches against the path-part of the URL only, ie. /en/brand/Abc. An additional complication in per-directory .htaccess files is that the URL-path that is matched is also less the directory prefix (which always starts with a slash), so the URL-path does not start with a slash. In other words: en/brand/Abc (for an .htaccess file in the document root).

So, you will need to format the directive like this instead:

RewriteRule ^en/brand/Abc$ https://www.example.co/en/brand/abc [R=301,L]

(Assuming you already have RewriteEngine On defined and that this is near the top of your .htaccess file.)

Reference:

Upvotes: 3

Related Questions