[英]Redirect file url to another page in .htaccess
I need to redirect all php files from end of urls to a specif dir like:我需要将所有 php 文件从 url 末尾重定向到特定目录,例如:
http://example.com/dir/file.php
http://example.com/dir/folder/file.php
http://example.com/dir/folder/folder2/file.php
to至
http://example.com/dir2/file.php
my code is我的代码是
RewriteRule ^(.*).php$ http://example.com/dir2/$1.php [R=301,L]
but I'm getting但我得到
http://example.com/dir2//dir/file.php
You can use the following:您可以使用以下内容:
RewriteRule ^.*/?([^/.]+).php$ http://example.com/dir2/$1.php [R=301,L]
This will just capture /file.php
in the regex and not the directory.这只会在正则表达式而不是目录中捕获
/file.php
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.