[英]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]
任何人都知道如何在第一个 RewriteRules 之后设置自定义重定向?
附: 甚至@anubhava 的答案都不起作用( htaccess 重定向不起作用)
您的正则表达式模式是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]
顺便说一句,我认为此问题与链接的答案没有关系(该答案用于添加www
和https
)
希望这次我的回答对你有用:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.