Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - Server
User Name
Linux - Server This forum is for the discussion of Linux Software used in a server related context.


  Search this Thread
Old 08-27-2007, 02:25 AM   #1
LQ Newbie
Registered: Jun 2007
Distribution: Ubuntu, Gentoo
Posts: 10

Rep: Reputation: 0
Apache2 mod_rewrite rule for changing file extentions

I want to make a mod_rewrite rule that performs the following, but I'm failing to get the logic in order:

1) Does [filename] end in .XYZ?
2) Does [filename].ABC exist?
3) If yes, redirect [filename].XYZ to [filename].ABC. If no, do nothing.

I could just do a blunt redirect with:
RewriteRule ^(.+)\.XYZ$ $1.ABC [R=301,L]
...which works, but I don't like the idea of doing a redirect to another non-existent file, so I'd like to check if it actually exists first.

I know I can accomplish 1) with:
RewriteCond %{REQUEST_FILENAME} ^(.+)\.XYZ$

and I know I can check for files existing with:
RewriteCond %{REQUEST_FILENAME} -f

The problem is, since the filename is dynamic, and we're not checking for the actual requested file, I don't know how to do a RewriteCond -f against the potential new filename.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Apache2 mod_rewrite isn't working vargadanis Linux - Server 3 11-09-2009 09:21 PM
mod_rewrite - rule to change http to https Firebar Linux - Server 10 06-05-2007 08:29 AM
mod_rewrite rule question jmoschetti45 Linux - Software 0 03-19-2007 08:29 PM
how to add mod_rewrite to apache2 scabrous1 Linux - Software 1 07-07-2006 10:48 AM
changing file extentions Seraph Linux - Newbie 3 09-17-2003 03:42 PM > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 08:58 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration