htaccess works without problem when i`m using english characters.
but when I use not english characters, it cant redirect and shows :
Not Found
The requested URL
these are my sample code. I have tasted it different types but nono of them works :
Redirect 301 "/مقاله-انواع-دسته-بندی-برج-های-خنک-کننده" /destination
Redirect 301 "/%D9%85%D9%82%D8%A7%D9%84%D9%87-%D8%A7%D9%86%D9%88%D8%A7%D8%B9-%D8%AF%D8%B3%D8%AA%D9%87-%D8%A8%D9%86%D8%AF%DB%8C-%D8%A8%D8%B1%D8%AC-%D9%87%D8%A7%DB%8C-%D8%AE%D9%86%DA%A9-%DA%A9%D9%86%D9%86%D8%AF%D9%87" /destination
Add the following line in your Apache configuration file:
AddDefaultCharset UTF-8
then restart your Apache server. After this, you may use your htaccess file which contains redirects with UTF-8 characters, and they should now be recognized. You should make sure that you save your htaccess file in a format which supports UTF-8.
You can use this rule in your site root .htaccess:
RewriteEngine On
RewriteRule ^مقاله-انواع-دسته-بندی-برج-های-خنک-کننده/?$ /destination [L,B,R=301]
Related
How can redirect localhost/DM/index/fb1ffc41 to localhost/DM/fb1ffc41 via .htaccess file.
fb1ffc41 this code is for short URL similar like Google short URL service.
Try the following at the top of the .htaccess file in the document root:
RewriteEngine On
RewriteRule ^DM/index/([a-f0-9]+)$ /DM/$1 [R,L]
This assumes the "short code" is 1 or more hexadecimal digits.
This is a temporary (302) redirect.
I am trying to redirect a subfolder as well as anything after it to the home page.
For example:
example.com/subfolder/extra-stuff > example.com
The extra-stuff is constantly changing and auto generated, so I want the redirect to remove that as well.
I am using:
Redirect 301 /subfolder(.*) http://www.example.com
However, this will result in http://www.example.com/extra-stuff.
Is there a way I can say if /subfolder(and anything else after subfolder) redirect to home?
Thanks for any suggestions!
The Redirect directive uses simple prefix-matching and everything after the match is copied onto the end of the target URL (which is what you are seeing here). However, the Redirect directive also does not support regex syntax, so a "pattern" like (.*) on the end will actually match the literal characters (, ., * and ) - which shouldn't have worked in your example?!
You'll need to use RedirectMatch instead (also part of mod_alias), which does use regex, and is not prefix matching.
For example:
RedirectMatch 301 ^/subfolder http://www.example.com/
Any request that starts /subfolder will be redirected to http://www.example.com/ exactly.
You'll need to clear your browser catch before testing.
You tagged your question "Magento" (which is probably using mod_rewrite). You should note, however, if you are already using mod_rewrite for rewrites/redirects then you should probably be using mod_rewrite instead of mod_alias to do this redirect, since you can potentially get conflicts.
For example, the equivalent mod_rewrite directive would be:
RewriteRule ^subfolder http://www.example.com/ [R=301,L]
Note there is no slash prefix on the RewriteRule pattern. This would need to go near the top of your .htaccess file.
Everyone who have tried to search through error_log files from large websites got lots of links like these bellow due to people who have screwd up some html in third part sites or blogs...
File does not exist: /var/www/vhosts/mydomain.com/httpdocs/materias/137.html'http://...
File does not exist: /var/www/vhosts/mydomain.com/httpdocs/materias/137.html http://...
File does not exist: /var/www/vhosts/mydomain.com/httpdocs/materias/137.html/mydomain...
The problem is some extra chars after the .html...
Its easy to guess the correct url in each case... we just have to truncate the url after the ".html".
Is it possible with .htaccess to rewrite these problematic urls to the correct syntax?
Just eliminating everything after the .
html? And avoiding messing up with url queries in dynamic urls?
Here's what I would like to do ...
Replace ".html " with ".html#"
Replace ".html'" with ".html#"
Replace ".html/" with ".html#"
As everything after the # will be just ignored...
Any simple way to do that with .htaccess?
Just use a Regex:
RewriteRule ^(.*)\.html(.*)$ $1.html
This RedirectMatch rule should work:
RedirectMatch 301 ^(.+?\.html).+$ $1
In my http logs I see:
"GET /category/f%C2%ADile-to-download/ HTTP/1.1" 301
instead of "GET /category/file-to-download/ HTTP/1.1" 200
I discovered that %C2%AD is a soft hyphen (invisible symbol).
I need to check if a query to Apache contains a soft hypen and if it does to remove it. Any suggestions on the best method to locate soft hyphen and remove it?
I made some tests with RewriteRule, but got stuck.
Thanks!
As I understand it, mod_rewrite uses un-escaped characters, so in order for you to correctly match the soft-hyphen and then remove it, you would need to edit and save your .htaccess file in UTF-8 encoding (most modern editors will do this).
You will then need to enter a soft-hyphen into your rule. The following will (should!?) remove a single soft-hyphen from your input, but as mentioned it relies on the file being in UTF-8 format:
RewriteRule ([^-]*)-([^-]*) $1$2
Note that you would need to replace the - with the actual UTF-8 dash.
Perhaps an easier option would be this:
RewriteRule ([^\xc2\xad]*)\xc2\xad([^\xc2\xad]*) $1$2 [N]
It uses the specific UTF-8 code you're seeing to remove it from the string. The [N] should rerun all the rewrite rules, which will remove any remaining soft-hyphens.
Thanks #icabod
Currently I got this rule working in my case:
RewriteCond %{REQUEST_URI} \xc2\xad [NC]
RewriteRule ([^\xc2\xad]*)[\xc2\xad]+([^\xc2\xad]*) /$1$2 [N,R=301,L,NC]
.htaccess should be in UTF-8 format as mentioned above.
R=301 - redirect with HTTP code 301
NC - case insensitive
But it doesn't work with two soft hyphens in the different places of the URL like this:
/category/f%C2%ADile-to-d%C2%ADownload/
Putting this at the top of my htaccess file doesn't do anything:
Redirect 301 /taxonomy/term/6%207%208%209 http://mysite.com/taxonomy/term/all
Neither does this:
Redirect 301 http://mysite.com/taxonomy/term/6%207%208%209 http://mysite.com/taxonomy/term/all
Im using a CMS that uses its own htaccess file so could it be my rule are being overridden? I thought that putting the code at the top of the file would solve this? Thanks
Escapes get decoded before going through mod_alias, so the %20's get turned back into spaces. You need to put them in quotes:
Redirect 301 "/taxonomy/term/6 7 8 9" http://mysite.com/taxonomy/term/all