Zach
Zach

Reputation: 442

Htaccess internal redirect for specific file not working

I currently use the following htaccess code to remove all .php extensions:

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{REQUEST_FILENAME} \.php$
RewriteRule .* - [F]

RewriteCond %{REQUEST_FILENAME} !-f    
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+[^/])/?$ $1.php [L]

ive been trying to use the following htaccess code to internally redirect or add a hidden query parameter to a file

RewriteRule ^myfile/?([^/])?/?$ myfile.php?m=$1 [L]

but it does not work.

Upvotes: 2

Views: 165

Answers (1)

anubhava
anubhava

Reputation: 785196

Order of rules in .htaccess is important so your new rule should be above all other rules. This should be your .htaccess:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteRule ^myfile/?([^/])?/?$ myfile.php?m=$1 [L,QSA,NC]

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{REQUEST_FILENAME} \.php$
RewriteRule .* - [F]

RewriteCond %{REQUEST_FILENAME} !-f    
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+[^/])/?$ $1.php [L]

Upvotes: 1

Related Questions