htaccess的重定向动态URL不工作 [英] htaccess redirect for dynamic urls not working
本文介绍了htaccess的重定向动态URL不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我基本上要:
http://example.com/index.php?page=abc 以重定向到 http://www.exmaple.com/abc
我有:
的RewriteCond%{QUERY_STRING} ^页=(。*)$
重写规则^的index.php $%1? [R = 301]
重写规则^%1 $的index.php?网页=%1 [L]
解决方案
在你的第二个规则和逻辑的人一些语法问题,在你的第一个规则。
下面应该工作:
RewriteEngine叙述上
#外部重定向,`的index.php?网页= abc`到`/ abc`
的RewriteCond%{THE_REQUEST} ^ [AZ] {3,} \ S / +指数\ .PHP \页=([^ \ S&安培] +)?[NC]
重写规则^ /%1? [R = 301,L]
#内部重定向从`/ abc`为`的index.php?网页= abc`
的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d
重写规则^([^ /] +)/ $ /index.php?page=$1 [L,QSA]
PS:我建议你阅读: URL重写简介
I basically want:
http://example.com/index.php?page=abc to redirect to http://www.exmaple.com/abc
I have:
RewriteCond %{QUERY_STRING} ^page=(.*)$
RewriteRule ^index.php$ %1? [R=301]
RewriteRule ^%1$ index.php?page=%1 [L]
解决方案
Some syntax issues in your 2nd rule and logic ones in your 1st rule.
Following should work:
RewriteEngine On
# for external redirection from `/index.php?page=abc` to `/abc`
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+index\.php\?page=([^\s&]+) [NC]
RewriteRule ^ /%1? [R=301,L]
# for internal redirection from `/abc` to `/index.php?page=abc`
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ /index.php?page=$1 [L,QSA]
PS: I suggest you to read: Apache mod_rewrite Introduction
这篇关于htaccess的重定向动态URL不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文