.htaccess RewriteRule examples


This is the source.

I’m copying it for just in case it get’s lost for some reason.

  1. If http://example.com/foo/bar does not exist, redirect to http://other.example.com/foo/bar. (Put this in an .htaccess file in your top-level web directory.)
  2. Handle all requests for top-level .html files and files with no extensions (http://example.com/foo,http://example.com/foo.html) with a single PHP program /foo/show.php. Also, ignore trailing characters in set { : ; , . } so URLs like “http://example.com/foo.” can be copied-n-pasted from plain text sentences by inattentive users.

    Examples:
  3. Redirect GET requests for http://example.com/foo/bar to http://example.com/bar (and/foo/bar.html to /bar.html). Handle POST requests with PHP program rather than attempting to redirect a POST (which is unlikely to work well).

    Examples:
Spread the love
,

Leave a Reply

Your email address will not be published. Required fields are marked *