Rewrite url rule with french accents - .htaccess

I am trying to redirect a URL with french accents to another URL without them.
Not sure what I am missing because it doesn't work
RewriteCond %{REQUEST_URI} ^\/content\/dam\/gwl\/documents\/s7\_000336fr\_Donnéesfinancières\.pdf$
RewriteRule .* https://%{HTTP_HOST}/fr/vous-et-votre-famille/formulaires/formulaires-de-demande-de-reglement-de-regimes-collectifs/formulaires-de-demande-de-reglement-standards.html [R=301,L]

Maybe so:
RewriteRule ^_Donn%C3%A9esfinanci%C3%A8res(.*)$ http://www.example.fr/_donneesfinancieres.html [L,R=301]
Another way is under .htaccess - How to redirect uppercase and accented letters to unaccented lowercase in url?

Related

Discard RewriteRule in htaccess

There are 2 RewriteRules for permalink in php.
RewriteRule ^(.*).htm index.php [NC,QSA,L]
RewriteRule ^(.*).html index.php [NC,QSA,L]
I need to browse a static html file:
/uploads/themes/mail-signature/mail-signature.html
But when I enter http://example.com/uploads/themes/mail-signature/mail-signature.html it's showing index.php.
How can I discard these rules?
RewriteRule ^(.*).htm index.php [NC,QSA,L]
RewriteRule ^(.*).html index.php [NC,QSA,L]
Your 2nd rule isn't actually doing anything anyway, since any .html requests will be caught by the first rule. So, the second rule can be removed.
You then add a condition to the first rule that excludes the specific URL you are trying to access. For example:
RewriteCond %{REQUEST_URI} !^/uploads/themes/mail-signature/mail-signature\.html$
RewriteRule \.html?$ index.php [NC,L]
The QSA flag is not required here, as any query string will be passed through by default.
The ^(.*) prefix on your RewriteRule pattern is not required since you aren't using this backreference.
You should backslash escape any literal dots in the regex, eg. \.htm, otherwise you are matching any character, eg. "xhtm". And presumably you only want to match URLs that end in .htm or .html? Your original regex would match "htm" anywhere in the requested URL.

301 Redirect URLs with capital letters and more than one forward slash

I need to permanently redirect URLs with capital letters and any number of forward slashes that appears after domain root back to the root.
Examples:
http://www.example.com/abc/pqr/23423532
(this has 2 forward slashes)
http://www.example.com/AngryBirds
(this has 2 capital letters)
Should be redirected to http://www.example.com/
Tried the following in https://www.regextester.com/
^(.*[\/?)$
^([\w]+)(\/+)$
^([A-Z]+)(\/?)
How can I write the regex expression to match these requirements?
Try with below,
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/([A-Z]+) [OR]
RewriteCond %{REQUEST_URI} ^/([/]{2,})
RewriteRule ^ http://www.example.com/ [R=301]

Rewrite url to url without html ending (.html)

I would like to redirect (301) all urls without .html to .html.
Example:
example.com/site should be redirected to example.com/site.html
I tried the following:
RewriteRule (.+)$ /$1.html [L,R=301]
Your rule is likely to cause a redirect loop, because it would rewrite the URL even after it has already been redirected.
In your pattern you need to make sure that the URL does not end with .html already.
You could use a negated pattern to achieve this:
RewriteRule !\.html$ %{REQUEST_URI}.html [L,R=301]
Alternatively, if you do not want to apply this for empty paths (such as in your example) or need to reuse the matches of your pattern, you could use a RewriteCondition:
RewriteCond %{REQUEST_URI} !\.html$
RewriteRule (.+)$ $1.html [L,R=301]
Note that this is a very simple example which only works for the exact case you described. This would also rewrite URLs ending with .htm to .htm.html, which might or might not be what you want.

Prevent redireting for a specific URL

I'm redirecting if the url contains a specific word.
RewriteRule ^forum(/.*)?$ /homepage.html?no=%{QUERY_STRING} [R=301,L,NE,NC]
Is it possible to avoid redirecting for a specific url that has the above specific word?
E.g.
The below gets redirect
http://www.exsample.com/forum/contactus.html?ypin9001234
to
http://www.exsample.com/homepage.html?no=ypin9001234
What I need is to continue the above redirect as it is but to avoid the redirect only for the below URL.
http://www.exsample.com/forum/members/gold/gold.html?ypin9001234
Note: The word gold is used only by this url.
You should use a RewriteCond with THE_REQUEST to match full URL with query string:
RewriteCond %{THE_REQUEST} !/forum/members/gold/gold\.html\?ypin9001234 [NC]
RewriteRule ^forum(/.*)?$ /homepage.html?no=%{QUERY_STRING} [R=301,L,NE,NC]
You can add a rewrite condition before your rewrite rule, e.g.:
RewriteCond %{REQUEST_URI} !^.*gold.*$
RewriteRule ^forum(/.*)?$ /homepage.html?no=%{QUERY_STRING} [R=301,L,NE,NC]
This will prevent any url containing the word gold from being rewritten. If you need to be more specific, just make the condition more precise:
RewriteCond %{REQUEST_URI} !^forum/members/gold.*$
RewriteRule ^forum(/.*)?$ /homepage.html?no=%{QUERY_STRING} [R=301,L,NE,NC]
etcetera...

301 Redirecting Multiple Pages

My rewrite rule almost works but there are still some problems. Here is the code:
RewriteEngine on
RewriteRule ^tag/(.*)$ /?s=$1&search=GA [L,R=301]
The first problem now is that the redirect links to:
mydomain.com/?s=tag/&search=GA
How can I get rid of the second slash?
Now the second problem... when a tag contains more than 1 word (for example the tag marketing tips) the redirect is:
mydomain.com/?s=marketing-tips/&search=GA
How do I convert that - symbol to a + symbol?
Try this:
# getting rid of trailing slash:
RewriteRule ^tag/(.*?)/?$ /?s=$1&search=GA [L]
# change "-" with "+":
RewriteCond %{QUERY_STRING} ^s=([^&]+)-([^&]+)&(.*)
RewriteRule ^(.*)$ /$1?s=%1+%2&%3 [L,NE]
# if there's no more "-", redirect:
RewriteCond %{QUERY_STRING} ^s=([^&-]+)(&|$)
RewriteRule ^(.*)$ /$1 [L,R=301]
When I go to a URL like mydomain.com/tag/some-thing-else-lots-of-dashes/, I get redirected to mydomain.com/s=some+thing+else+lots+of+dashes&search=GA
It looks like your regex is picking up the slash from the incoming URL in it's collection, try moving it out and making it optional, also I made your selector less greedy:
RewriteRule ^tag/(.*?)/?$ /?s=$1&search=GA [L,R=301]

Resources