Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
301.htaccess中的重定向_.htaccess_Url Redirection_Http Status Code 301 - Fatal编程技术网

301.htaccess中的重定向

301.htaccess中的重定向,.htaccess,url-redirection,http-status-code-301,.htaccess,Url Redirection,Http Status Code 301,我正在尝试使用.htaccess文件中的以下行重定向URL: redirect 301 /old_file_path /new_file_path 重定向工作正常,但我得到的URL格式不同: /new_file_path/?/old_file_path 如何修复此问题?您应该重定向到完整的新路径: redirect 301 /old_file_path https://example.com/new_file_path 请遵循以下示例: Redirect 301 /oldpage.html

我正在尝试使用.htaccess文件中的以下行重定向URL:

redirect 301 /old_file_path /new_file_path
重定向工作正常,但我得到的URL格式不同:

/new_file_path/?/old_file_path

如何修复此问题?

您应该重定向到完整的新路径:

redirect 301 /old_file_path https://example.com/new_file_path

请遵循以下示例:

Redirect 301 /oldpage.html http://www.yoursite.com/newpage.html
Redirect 301 /oldpage2.html http://www.yoursite.com/folder/
或者与您共享完整的.htaccess文件,以便我们更好地查看

确保mod_rewrite apachi模块已打开

我在最后测试了代码,它运行良好

RewriteEngine on
Redirect 302 /master-trainer https://www.keleven.com/master_trainer_course

我希望它能有所帮助。

像这样单独使用
重定向
指令一开始就不能产生这种效果。PHP与此有什么关系?使用HTTP协议/文件夹/文件作为第二个参数,而不是系统路径。这是你的完整代码吗?好像少了一些零件。还有,这运行的是哪个操作系统?试试看
RewriteRule^/old\u file\u path(.*)$/new\u file\u path$1[R=301,NC,L]
噢,我的错。我使用的代码是:重定向301/旧文件路径/新文件路径旧URL:新URL:我得到的URL:必须有一种方法不必硬编码服务器路径重定向301/主培训师https://www.keleven.com/master_trainer_course这就是我使用的,假设它工作正常,我在本地主机上进行测试,结果很好。