0

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.

ckliborn
  • 2,778
  • 4
  • 25
  • 37
  • 1
    You don't want to try to compare `%{REQUEST_URI}` with your filesystem, since it's not supposed to ever contain a filesystem object. – Ignacio Vazquez-Abrams May 16 '12 at 15:13
  • Not sure what you mean. I am checking for the existence of a file - ex: /var/www/html/page1.html - For www.domain.com, the URI would be page1.html – ckliborn May 16 '12 at 15:22

1 Answers1

2
RewriteCond %{REQUEST_FILENAME} (.*)\.html
RewriteCond %{REQUEST_URI} (.*)\.html
RewriteCond %1.shtml -f
RewriteRule (.*) http://new.example.com%2.shtml
Ignacio Vazquez-Abrams
  • 45,939
  • 6
  • 79
  • 84
  • Would you be able to add some description on what this is doing? I'm having a little trouble following it. – ckliborn May 30 '12 at 15:49
  • http://serverfault.com/questions/394021/how-can-i-test-for-a-urls-existeance-before-redirecting-to-it Here is where I am looking for a little more help – ckliborn May 30 '12 at 15:58
  • It compares the request filename (in the filesystem) with `.*\.html` and then stores the prefix in `%1`. It then compares the request URL path with the same, and stores the prefix in `%2`. – Ignacio Vazquez-Abrams May 30 '12 at 16:15
  • my mobile document root (/var/www/m/) is different than my "full" site (/var/www/html/) - How do I take that into account? – ckliborn May 30 '12 at 16:43
  • Modify the check against `%{REQUEST_FILENAME}` appropriately to remove those three components, then fix up the third condition. – Ignacio Vazquez-Abrams May 30 '12 at 16:55