问题
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
回答1:
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]
回答2:
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]
来源:https://stackoverflow.com/questions/27600684/htaccess-redirection-for-php-files-only-to-another-url