1

I am trying to rewrite the whole contents of a directory to the home url.

so, if someone visits www.example.com/bnn27sh32j@d299/gold it should take them to www.example.com/gold

I have tried:

RewriteRule ^bnn27sh32j@d299/(.*)$ /$1 [R=301,NC,L]

doesnt work, maybe its because it has the illegal characters in the dir name?

  • Here is a similar problem on StackOverflow where somebody is trying to rewrite an encoded @: stackoverflow.com/questions/26130493/… – Stephen Ostermiller Apr 19 '18 at 13:38
  • 1
    What other rewrite rules do you have in place? It could be a conflict of some kind. The order of the rules could be an issue. – Stephen Ostermiller Apr 20 '18 at 13:43
  • There is nothing "illegal" about the @ (at) character - if that is what you are implying? (Although you mention "characters"? What other "illegal" characters are there?) The @ character is nothing special, it does not need to be URL encoded in the path part of the URL and is matched as a literal character by the RewriteRule pattern (even if it was URL encoded in the request). FWIW, your RewriteRule directive by itself looks OK, so maybe there is a conflict elsewhere in your .htaccess file, as @Stephen suggests? – MrWhite Apr 26 '18 at 22:05
  • 1
    However, you've tagged your question nginx? RewriteRule and .htaccess are an Apache mechanism and will obviously not work on Nginx? – MrWhite Apr 26 '18 at 22:05
1

Try this:

RedirectMatch 301 ^/bnn27sh32j@d299/(.*) http://www.example.com/$1

It takes http://www.example.com/bnn27sh32j@d299/gold and redirects to http://www.example.com/gold.

Before implementing, you can test the rule here: https://htaccess.mwl.be/

  • Although this is really no different to the rule stated in the question? (If one works then so should the other, except for conflicts with other directives). – MrWhite Apr 20 '18 at 12:20

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.