: Redirect percent encoded URL in .htaccess Suppose I have the following URL: http://example.com/%D8%B3%DB%8C%D8%B3%D8%AA%D9%85-rss-%D8%B3%D8%A7%DB%8C%D8%AA-%D8%A8%D9%87%DB%8C%D9%86%D9%87-%D8%B4%D8%AF/ How can
Suppose I have the following URL:
example.com/%D8%B3%DB%8C%D8%B3%D8%AA%D9%85-rss-%D8%B3%D8%A7%DB%8C%D8%AA-%D8%A8%D9%87%DB%8C%D9%86%D9%87-%D8%B4%D8%AF/
How can I redirect this to www.example.com?
More posts by @Pierce454
1 Comments
Sorted by latest first Latest Oldest Best
You can use mod_alias RedirectMatch, for example:
RedirectMatch ^/سیستم-rss-سایت-بهینه-شد/$ www.example.com/
Note that the URL-path matched by RedirectMatch is %-decoded.
However, if you are already using mod_rewrite (ie. RewriteRule) for other redirects then you should use mod_rewrite instead to avoid chance of conflict. For example, in .htaccess:
RewriteRule ^سیستم-rss-سایت-بهینه-شد/$ www.example.com/ [R,L]
The URL-path matched by the RewriteRule pattern is also %-decoded. But does not start with a slash in per-directory .htaccess files.
Note that these are both temporary (302) redirects. To make them permanent (301) you need to explicitly include the status. ie. RedirectMatch 301 and R=301 respectively.
EDIT: If you did specifically want to match against the %-encoded URL (as seen in the request) then you can match against THE_REQUEST, for example:
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9} /%D8%B3%DB%8C%D8%B3%D8%AA%D9%85-rss-%D8%B3%D8%A7%DB%8C%D8%AA-%D8%A8%D9%87%DB%8C%D9%86%D9%87-%D8%B4%D8%AF/
RewriteRule ^ www.example.com/ [R,L]
THE_REQUEST server variable is not %-decoded before being passed to mod_rewrite.
However, this is now dependent on the requested URL being encoded exactly as stated. It is also marginally less efficient since every request will be processed by the RewriteRule and passed to the preceding condition.
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.