Taha
Taha

Reputation: 55

htaccess redirection for php files only to another url

I want to redirect my php files inside a specific folder to another url , the htacess file that i used is working for php files but also with other extensions and for my case i want only php files to be redirected to the new url that's the htaccess:

   RewriteEngine On
   RewriteCond %{HTTP_HOST} !^ml\.mysite1\.com/fr/test2/^(.*\.php)$
   RewriteRule (.*) http://mysite2.com/$1 [R=301,L]

My question is about how can i only redirect *.php and not other extension ( jpg, png etc )

Thanks

Upvotes: 0

Views: 243

Answers (2)

anubhava
anubhava

Reputation: 785128

You cannot match Request URI in %{HTTP_HOST} condition.

RewriteEngine On

RewriteCond %{HTTP_HOST} !^ml\.mysite1\.com$
RewriteRule ^fr/test2/(.+?\.php)$ http://mysite2.com/$1 [R=302,L,NC]

Upvotes: 2

Philip Adler
Philip Adler

Reputation: 2206

Your third line needs to be changed so that it only matches files with the php extension.

RewriteRule (.*)\.php http://mysite2.com/$1.php [R=301,L]

Upvotes: 0

Related Questions