Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|improve this question
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
add comment

1 Answer

up vote 2 down vote accepted
RewriteCond %{REQUEST_FILENAME} (.*)\.html
RewriteCond %{REQUEST_URI} (.*)\.html
RewriteCond %1.shtml -f
RewriteRule (.*) http://new.example.com%2.shtml
share|improve this answer
    
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
    
serverfault.com/questions/394021/… 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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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