Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Rewrite additional extension

Posted on 2009-05-07
3
Medium Priority
?
226 Views
Last Modified: 2012-05-06
I want to rewrite all urls so so the extension .txt is appended (unless it already has a .txt extension)

This
     hello.php
should be re-written to
     hello.php.txt

This
     hello
should be re-written to
     hello.txt

This
     hello.js
should be re-written to
     hello.js.txt

This
     hello.txt
should NOT be rewritten


       
0
Comment
Question by:hankknight
  • 2
3 Comments
 
LVL 8

Expert Comment

by:thetmanvn
ID: 24328183
If you give more details about your case, it will be more accuracy

From your needs, add two rules to your rewrite portion:

RewriteRule ^(.*\.txt)$ $1 [L]
RewriteRule ^(.*\..*)$ $1\.txt [L]
0
 
LVL 16

Author Comment

by:hankknight
ID: 24328226
How can I make it so

test.txt

does not go to

test.txt.txt

?
0
 
LVL 8

Accepted Solution

by:
thetmanvn earned 2000 total points
ID: 24328293
Test my rule and you've got it. (You can add this to .htaccess in one test folder to test yourself, create 3 file a.txt, b.php and c.js in the same folder with .htaccess, browse 3 files with your browser and you will see the result)

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*\..*)$ $1\.txt [L]
</IfModule>

1./ The first rule RewriteRule ^(.*\.txt)$ $1 [L] check whether the URI  end with ".txt", in this case, it remain the URI, so test.txt does not go to test.txt.txt.   The [L] Flag tell this is the last rule so the second rule will not be processed

2./ If the file does not end with .txt so the first rule was bypassed, then come to the second rule, it check whether URI has extension, if yes it'll add .txt to end of URL, so b.php -> b.php.txt, c.js -> c.js.txt
0

Featured Post

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my time as an SEO for the last 2 years and in the questions I have assisted with on here I have always seen the need to redirect from non-www urls to their www versions. For instance redirecting http://domain.com (http://domain.com) to http…
Over the last year I have answered a couple of basic URL rewriting questions several times so I thought I might as well have a stab at: explaining the basics, providing a few useful links and consolidating some of the most common queries into a sing…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses
Course of the Month12 days, 2 hours left to enroll

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question