Baoky chen
Baoky chen

Reputation: 99

HTaccess conflict with each other on php rewrite and file

I have this original .htaccess at my folder

/subfolder/offer/dl

AddType application/octet-stream .txt

The purpose was to force direct download on txt file on click on any .txt extension e.g

http://example.com/subfolder/offer/dl/1.txt 

The above url will download the txt file instead of show it at browser.

Then recently at the folder offer, I added the following .htaccess

RewriteEngine On
RewriteBase /subfolder/offer/

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/?$ index.php?action=$1 [QSA,L]
RewriteRule ^([^/]+)/([^/]+)/?$ index.php?action=$1&action_id=$2 [L,QSA]

Now due to this .htaccess, my above .htaccess for /dl folder doesn't work, it won't download or link to the file

What should I change to make both works.

Upvotes: 1

Views: 46

Answers (1)

anubhava
anubhava

Reputation: 785256

You can just add a rule to ignore all requests inside /dl/ folder:

RewriteEngine On
RewriteBase /subfolder/offer/

RewriteCond %{REQUEST_URI} /dl/ [OR]
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]

RewriteRule ^([^/]+)/?$ index.php?action=$1 [QSA,L]

RewriteRule ^([^/]+)/([^/]+)/?$ index.php?action=$1&action_id=$2 [L,QSA]

Upvotes: 2

Related Questions