htaccess自定义重定向不起作用


htaccess Custom Redirects not working

我一直在到处找,但似乎不能使它工作。

代码运行正常:

RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^/?artists/['w-]+/(['w-]+)/(['w-]+)/?$ /dir1/artist.php?artist_id=$1&page_id=$1 [L,QSA,NC]
RewriteRule ^/?tour/['w-]+/(['w-]+)/?$ /dir2/index.php?artist_id=$1 [L,QSA,NC]
RewriteRule ^/?video/['w-]+/(['w-]+)/?$ /dir3/index.php?artist_id=$1 [L,QSA,NC]
RewriteRule ^/?news/['w-]+/(['w-]+)/?$ /dir4/article.php?artist_id=$1 [L,QSA,NC]

然而,在此之后,我尝试下面的操作,服务器根本没有响应。它只是加载旧页面(仍然在服务器上)

我的自定义重定向尝试,已尝试但不工作

RedirectMatch 301 ^/old_dir//old_file.html /artists/subdir/21/biography/
RewriteRule /old_dir//old_file.html /artists/subdir/21/biography/ [L,R=301]

有人知道如何设置自定义重定向后的第一个rewriterrules ?

p。

@anubhava的答案不工作

您的正则表达式模式是301规则的问题:

RewriteEngine On
RewriteRule ^old_dir/old_file'.html$ /artists/subdir/21/biography/ [L,R=301,NC]
RewriteCond %{SCRIPT_FILENAME} -d [OR]
RewriteCond %{SCRIPT_FILENAME} -f
RewriteRule ^ - [L]
RewriteRule ^/?artists/['w-]+/(['w-]+)/(['w-]+)/?$ /dir1/artist.php?artist_id=$1&page_id=$1 [L,QSA,NC]
RewriteRule ^/?tour/['w-]+/(['w-]+)/?$ /dir2/index.php?artist_id=$1 [L,QSA,NC]
RewriteRule ^/?video/['w-]+/(['w-]+)/?$ /dir3/index.php?artist_id=$1 [L,QSA,NC]
RewriteRule ^/?news/['w-]+/(['w-]+)/?$ /dir4/article.php?artist_id=$1 [L,QSA,NC]

btw我看到这个问题与链接的答案没有关系(答案是添加wwwhttps)

希望我的回答这次对你有用