Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/11.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
.htaccess 重定向在htaccess中不起作用_.htaccess - Fatal编程技术网

.htaccess 重定向在htaccess中不起作用

.htaccess 重定向在htaccess中不起作用,.htaccess,.htaccess,我有这样一个链接: /add.php?id=50&link=page2 我希望它重定向到以下位置: /add/50/page2 我该怎么做?我尝试了以下方法,但无效: Redirect /add.php?id=50&link=page2 /add/50/page2 您可以在文档\u ROOT/.htaccess文件中使用此代码: Options -MultiViews RewriteEngine On RewriteBase / # external redirect

我有这样一个链接:

/add.php?id=50&link=page2
我希望它重定向到以下位置:

/add/50/page2
我该怎么做?我尝试了以下方法,但无效:

 Redirect /add.php?id=50&link=page2 /add/50/page2

您可以在
文档\u ROOT/.htaccess
文件中使用此代码:

Options -MultiViews
RewriteEngine On
RewriteBase /

# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} /add\.php\?id=([^\s&]+)&link=([^\s&]+) [NC]
RewriteRule ^ add/%1/%2? [R=302,L,NE]

# internal forward from pretty URL to actual one
RewriteRule ^add/([^/.]+)/([^/.]+)/?$ add.php?id=$1&link=$2 [L,QSA,NC]

我认为它需要第三个参数:
Redirect/add.php?id=50&link=page2/add/50/page2-MakeItWork
这是在我的Apache上经过充分测试和运行的代码。确保已启用mod_rewrite。如果已启用,请检查Apache error.log以了解错误原因