This question already has an answer here:

I'm trying to write a RewriteRule to make a simple url. I want users to be able to type enter


and have it take them to


How can this be done in .htaccess?

I've tried these to no avail:

RewriteRule ^somepage$ abc/somepage.php [L]

RewriteRule ^/somepage$ /abc/somepage.php [L]

Your help is much appreciated.

marked as duplicate by Su', Simon Hayter, John Conde May 2 '13 at 11:42

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • As it turns out, this isn't a simple duplicate of the "Apache htaccess redirects" question, linked to above, since the answer is dependent on the nginx server. – MrWhite May 5 '13 at 10:59

Assuming this is in the .htaccess in your document root, then you are almost there. You just seem to be missing the / (slash - directory separator) from the front of your destination URL (in the first example).

RewriteEngine On
RewriteRule ^somepage$ /abc/somepage.php [R=301,L]

The slash (or whatever is the base URL) is automatically removed from the request URI when pattern matching, which is why it is not present in the pattern (^somepage$).

This will perform an external redirect (R=301) - so the destination URL will show in the browser. Remove the R flag to perform an internal rewrite (URL won't change).

  • Thanks for the response. This isn't working for me.. I have no idea why. And sorry, I meant to only have [L], so the dest url will not show in the user's browser. – Nick Rolando May 1 '13 at 18:46
  • This is the literal code: RewriteRule ^hatfinder$ /gbi/hatfinder.php [L] You can see it not working here: www.goorin.com/hatfinder – Nick Rolando May 1 '13 at 18:48
  • In what way "not working"? Does anything happen? Is mod_rewrite enabled? Is FollowSymLinks enabled? – MrWhite May 1 '13 at 18:49
  • Yes, they are both enabled. I'm getting 404 – Nick Rolando May 1 '13 at 18:51
  • 1
    So I figured it out.. the rewrites are handled in the .conf files for the nginx server. They can be done in .htaccess, but the .conf doesn't let it get that far it seems.. (not sure why we still have a .htaccess file), and you're right, in the .conf file it is written rewrite – Nick Rolando May 2 '13 at 15:36

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