May 30, 2012
tom

How can I store {REQU­EST­_URI} in a variable, manipulate it and then use it in a RewriteCond or RewriteRule

Question

How can I store {REQU­EST­_URI} in a variable, manipulate it and then use it in a RewriteCond or RewriteRule?

Basically, here is what I am looking to do.

1.) Get the {REQU­EST­_URI} and change .shtml to .html, store this in a variable called URL_MOD

2.) Test for the existence of a file with that name of the newly created Variable called URL_MOD

3.) Based on the test result, redirect users to a domain with the URL_MOD appended.

Asked by ckliborn

Answer

RewriteCond %{REQUEST_FILENAME} (.*)\.html
RewriteCond %{REQUEST_URI} (.*)\.html
RewriteCond %1.shtml -f
RewriteRule (.*) http://new.example.com%2.shtml

Related posts:

  1. Apache RewriteRule with a RewriteMap variable substitution for the VAL argument to environment variable
  2. mod_rewrite: Use backreference from RewriteCond as CondPattern in another RewriteRule
  3. How do I fix my usage of RewriteCond in our MediaWiki .htaccess file?
  4. Apache RewriteRule ignoring RewriteCond?
  5. RewriteRule applying pattern even though 1 of the RewriteCond’s failed

Leave a comment