1

I have URL like this: http://example.com/apple_a/

I am using this rule:

RewriteEngine On  
RewriteRule ^([^_]*)-+(.*)$ $1_$2 [L,NC]

this is replacing other URL's like http://example.com/apple/a_a/a_b to "http://example.com/apple/a-a/a-b" (underscore with dashes) but when I write "_" in first directory like this "http://example.com/apple-a/a-a/" then its throwing 404 error.

So I wants that working somehow. Please help.

1 Answer 1

1

Correct rule will be:

RewriteEngine On  
RewriteRule ^([^-]*)-+(.*)$ $1_$2 [L,NC]

You have ([^_]*) instead of ([^-]*)

10
  • I am trying this url : example.com/apple-a and its throwing 404 with above htaccess rule. Nov 27, 2013 at 7:14
  • Hmm I even tried /apple-a/a-b-c and it was internally rewritten to /apple_a/a_b_c
    – anubhava
    Nov 27, 2013 at 7:18
  • right, do you have any idea about fixing this? if yes please tell me. Nov 27, 2013 at 7:19
  • If you directly try http://example.com/apple-a does it load correct page? (http://example.com/apple-a doesn't get affected at all with this rule)
    – anubhava
    Nov 27, 2013 at 7:24
  • rest things are working fine. except if "-" will come in first part after domain. if I write like this example.com/apple_a/a-a/b-b than also its working fine. but not working with "apple-a". Nov 27, 2013 at 7:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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