Solved

Rewrite additional extension

Posted on 2009-05-07
3
207 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 500 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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

It is possible to boost certain documents at query time in Solr. Query time boosting can be a powerful resource for finding the most relevant and "best" content. Of course the more information you index, the more fields you will be able to use for y…
If you are a web developer, you would be aware of the <iframe> tag in HTML. The <iframe> stands for inline frame and is used to embed another document within the current HTML document. The embedded document could be even another website.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

813 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now