htaccess redirection for php files only to another url

爱⌒轻易说出口 提交于 2019-12-12 00:42:02

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!