I am trying to redirect
新闻/事件/finance-for-sdgs-high-level-meeting-bellagio-financeforsdgs-2/?lang=zh-hans
to
/finance-for-sdgs-high-level-meeting-financeforsdgs-bellagio-25-27-february-2015/?lang=zh-hans
but am not sure of the encoding. The following is not working:
RewriteRule ^æ°é»/äºä»¶/finance-for-sdgs-high-level-meeting-bellagio-financeforsdgs-2/?lang=zh-hans$ http://ecosequestrust.org/finance-for-sdgs-high-level-meeting-financeforsdgs-bellagio-25-27-february-2015/?lang=zh-hans [R=301,L]
You can try using the \x escape sequence to escape the Unicode:
RewriteRule ^\xE6\x96\xB0\xE9\x97\xBB\x2F\xE4\xBA\x8B\xE4\xBB\xB6/finance-for-sdgs-high-level-meeting-bellagio-financeforsdgs-2/$ http://ecosequestrust.org/finance-for-sdgs-high-level-meeting-financeforsdgs-bellagio-25-27-february-2015/ [R=301,L]
Essentially, replacing the 新闻/事件 with \xE6\x96\xB0\xE9\x97\xBB\x2F\xE4\xBA\x8B\xE4\xBB\xB6. This way, you don't need to rely on the encoding of the htaccess file.
Related
I tried to make redirection of the following URL:
https://www.domain.tld/%20rel=
to
https://www.domain.tld/
But it seems to be more complicated than what I thought.
Here are some of the methods I used in my .htaccess file:
RewriteRule ^%20rel=$ /?&%{QUERY_STRING}
RewriteRule ^%20rel=$ /? [L,R=301]
Redirect 301 /%20rel= https://www.domain.tld/
and others, but non worked for me. Can someone help with this issue?
You can use this rule:
RewriteEngine On
RewriteRule ^\x20rel=/?$ / [L,R=301]
You need to use \x20 to match %20 or in general use \xhh to match any %hh character.
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]
I'm having some issues with redirecting some pages with "%11" and "%28".
I'm trying to redirect a couple of pages, the rest work but I realized those with some symbols in it are not redirecting.
For example:
Redirect 301 /cars/mercedes%11benz/ http://www.example.com/cars/mercedes-benz/
Redirect 301 /alfa-romeo/alfa-romeo-147-%282001%E2%80%932009%29-2008090174/ http://www.example.com/cars/alfa-romeo-147/
do not work.
Thanks in advance for the help.
Basically specifies that only ASCII text is allowed. Might u having white spaces in url. Please remove them.
As for mod_rewrite, I believe that you've got that right except that the dot character in the character range need not be escaped, i.e., the hyphen is properly located at the beginning and the space is escaped. The ü probably doesn't need to be escaped but it shouldn't hurt). As for browsers making the conversion, that's a "browser thing" which Apache understands (and converts internally to the correct character).
Try this:
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /[^%?\ ]*\%
RewriteRule ^. http://www.example.com/ [R=301,L]
RewriteRule ^/cars/mercedes-benz/ http://www.test-site.com/cars/mercedes%11benz/ [QSA]
I want to allow special charecters in URL
my htaccess code is
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteRule ^blog/?$ SocialNetwork/blog.php [L]
RewriteRule ^blog/(\d+)/?$ SocialNetwork/blog.php?id=$1 [L]
RewriteRule ^blog.php/(\d+)/?$ SocialNetwork/blog.php?id=$1 [L]
RewriteRule ^blog.php/(\d+)/([A-Za-z0-9-_[]]+)/?$ SocialNetwork/blog.php?id=$1&title=$2 [L]
</IfModule>
it works for
blog/1
blog/1/hii
blog/1yooo_title
but does not work for
blog/1/[hii-this is [] title
In your last rewrite rule, try escaping the square brackets. Also if you need to match spaces you need to include \s in there:
^blog.php/(\d+)/([A-Za-z0-9-_\[\]\s]+)/?$
Or perhaps consider the simpler which accepts anything in the title:
^blog.php/(\d+)/(.+)/?$
Another point is that you should not have spaces in your URLs. They should be escaped to "+" or %20. So depending on this your regex would change, except the last one I proposed should work.
I'm pretty sure that you can't use spaces in a URL. Ever.
only alphanumerics, the special characters "$-_.+!*'(),", and reserved characters used for their reserved purposes may be used unencoded within a URL.
http://www.ietf.org/rfc/rfc1738.txt
How would I write a redirect rule that would let me use both http://www.site.com/rss and http://www.site.com/anydirectory/rss rather than http://www.site.com/rss.xml and http://www.site.com/anydirectory/rss.xml ?
I think I'm close, but for some reason, it's a Monday.
RewriteRule ^(.*)/rss.\xml/$ $1/rss [L]
I think this is what you want (you have them reversed):
RewriteRule ^(.+/)?rss$ $1rss.xml [L]
This is a guess, but it looks like you intended to escape the . and that is done with \. instead of .\
RewriteRule ^(.*)/rss\.xml$ $1/rss [L]
It sounds like you have the XML files, and you want to make URIs without the XML extension work.
# translate /rss to /rss.xml
RewriteRule ^rss$ /rss.xml
# translate /anydirectory/rss to /anydirectory/rss.xml
RewriteRule ^(.+)/rss$ /$1/rss.xml
The code you tried suggests the opposite.
# translate /rss.xml to /rss
RewriteRule ^rss\.xml$ /rss
# translate /anydirectory/rss to /anydirectory/rss.xml
RewriteRule ^(.+)/rss\.xml$ /$1/rss