I am finding strange character in url
%27A=0
Its either coming in middle or in between or end of url
How to escape and remove through htaccess the url having %27A=0
Server is running on apache and nginx
You can remove %27 (html escape for ampersend) from url with this line
RewriteRule ^(.*)'=0(.*)$ /$1$2 [R=301,L,NE]
Related
i have a issue on the website im working on, i have 2 urls, url1
https://www.fakeurl/fr/histoires-d-art/interview-peintre-anne-baudequin
and url2
https://www.fakeurl/fr/module/_edito/EditoContent?slug=interview-peintre-anne-baudequin
Both url display the same content but i want to redirect url2 to url1 using htaccess, the code i wrote in in htaccess is not working and i dont understand why. This is it
redirect 301 /fr/module/_edito/EditoContent?slug=interview-peintre-anne-baudequin https://www.fakeurl/fr/histoires-d-art/interview-peintre-anne-baudequin
I finally figured it out by myself, i had to change my code to this for it to work.
RewriteCond %{THE_REQUEST} ^(GET|POST)\ /fr/module/_edito/EditoContent\?slug=interview-peintre-anne-baudequin\ HTTP
RewriteRule ^ /fr/histoires-d-art/interview-peintre-anne-baudequin? [L,R=301]
The mod_alias Redirect directive matches against the URL-path only, not the question string, so the above does not match the requested URL.
You need to use mod_rewrite with an additional condition that matches against the QUERY_STRING server variable (or THE_REQUEST). However, you also need to be careful of redirect loops since I assume you are also using a front-controller (that internally rewrites URL1).
Try the following instead, at the top of your .htaccess file:
# Redirect URL2 to URL1
RewriteCond %{THE_REQUEST} ^[A-Z]{3,7}\s/fr/module/_edito/EditoContent\?slug=interview-peintre-anne-baudequin\sHTTP [NC]
RewriteRule ^ /fr/histoires-d-art/interview-peintre-anne-baudequin [QSD,R=301,L]
THE_REQUEST contains the first line of the request headers and does not change when the request is internally rewritten.
The QSD flag is necessary to remove the original query string from the redirect response.
Test first with a 302 (temporary) redirect to avoid potential caching issues.
UPDATE: Fixed regex to backslash-escape the literal ? and added slash prefix to the RewriteRule substitution string.
Google has indexed some URLs with empty value - space - at the end of each URL, I want to make a permanent redirect via .htaccess here is my code but it did not redirecting :
RewriteRule ^/profile/userx/([a-zA-Z])+/[a-zA-Z]+/[a-zA-Z]/'%20'$ https://mywebsite.net/profile/userx/([a-zA-Z]+)/[a-zA-Z]+/[a-zA-Z]/ [R=301,L]
How to say any URL with space at the end redirect it to that one without space?
You may use this rule as your topmost rule to remove 1+ whitespace from the end of URL:
RewriteEngine On
RewriteRule ^(.*)\s+$ /$1 [L,NE,R=301]
# other rules go below this line
\s+$ matches 1+ whitespace at the end of a URI and .* matches anything before whitespaces.
My URL is https://example.com/555
I want to use htaccess to redirect this to https://example.com/view.php?id=555
I know I need to use the RewriteRule as follows
RewriteRule ^(.*)$ https://www.example.com/view.php?id= [R=301,L]
How do I read and append the number in the URL to the script with htaccess?
Don't use R flag as it will redirect to your internal URL. Also to capture numbers just \d+ in regex:
RewriteRule ^(\d+)/?$ /view.php?id=$1 [QSA,L]
Having a Drupal here. In that Drupal is a folder with another Drupal. So in another Drupal's .htacces the base was rewritten like this Rewrite Base /another-drupal and everything's fine.
Now, printed invitations were send to customers to look at the another Drupal via its URL adrupal.com/another-drupal. And like right now the URL stands at the end of a sentence and the dot looks like it is part of the URL. How do I redirect all users who entered the URL with a trailing dot to the correct URL without the trailing dot? And in which .htaccess do I have to do that? The parent's Drupal .htacess? Or in the another Drupal's .htaccess?
I allready tried that approach: Redirect url to home page with trailing dots, but it didn't work. Is it maybe because in that example they have two dots?
Try:
RewriteCond %{THE_REQUEST} \ /([^\?\ .]*)\.(?:\?|\ |$)
RewriteRule ^ /%1 [L,R=301]
Looks like this simple rule is all you need:
RewriteRule ^(.+?)\.$ $1 [L,R=301]
This will remove trailing period (dot) from any URL.
I need to redirect multiple URLs with% character, through htaccess.
Currently the lines are:
RewriteEngine On
RewriteCond% {REQUEST_FILENAME}!-F
RewriteCond% {REQUEST_FILENAME}!-D
RewriteRule ^-.*$ url [R=301,L]
RewriteRule ^%20.*$ url redirection [R=301,L]
RewriteRule ^%22.*$ url redirection [R=301,L]
RewriteRule ^images/files/myname%is-fyle.pdf.*$ url redirection [R=301,L]
From these lines, the redirects do not work are:
RewriteRule ^%20.*$ url redirection [R=301,L]
RewriteRule ^%22.*$ url redirection [R=301,L]
RewriteRule ^images/files/myname%is-fyle.pdf.*$ url redirection [R=301,L]
Any ideas on what I'm doing wrong? My knowledge is basic almost, not quite understand why the redirects with % in the URL do not work.
I researched on the use of flags as noescape [NE], but I have not managed to get the redirects from the URLs with the character %.
("url redirection" in te lines of htaccess is the URL that being new to the forum I can not post).
Thank you.
Sep 23: I thank those who have helped me with this problem. However, the URLs with special characters (% and ?) and capital letters do not forward.
I copy and paste the complete code for my htaccess file:
Here: http://pastebin.com/yXGQiQzd
I saw in this post How to Redirect to a url containing an anchor (#)? that apparently the answer is posted. However, the matter is in the use of ([]) for the rule. The example is: ([a-zA-Z0-9-_]+)
In my case, for example, these URLs:
images/SchoolContry/wef/pdf/SomethingOfFiles/the reasons behind?s of the ca?da.pdf
images/stories/Money/memo Matric?cula 2010.doc
Any idea why URLs with special characters (% and ?), space and capital letters redirect not?
Thanks.
URL encoded characters get decoded before they're sent through the rewrite engine. That means you need to use the decoded characters to match against and not the encoded ones. So for:
RewriteRule ^%20.*$ url redirection [R=301,L]
you want:
RewriteRule ^\ .*$ url redirection [R=301,L]
and for:
RewriteRule ^%22.*$ url redirection [R=301,L]
you want:
RewriteRule ^\".*$ url redirection [R=301,L]