Mod用查询字符串重写URL到漂亮的网址
我用查询字符串中的几个参数成功地改变了我的网址,使用mod重写来清理看起来很丑的网址。但是,我的网站有很多网址。我试图在.htaccess文件中编写一个重定向函数,它会自动将旧URL重定向到新的重定向函数,而不是返回并编辑每个锚标记的href属性。Mod用查询字符串重写URL到漂亮的网址
在我的.htaccess文件,我有以下几点:
RewriteEngine On
Redirect teams.php?league=$1&team=$2&year=$3&tab=$4 teams/(.*)/(.*)/(.*)/(.*)
RewriteCond %{REQUEST_URI} !^(css|js|img)/
RewriteRule ^teams/([^/]*)/([^/]*)/([^/]*)/([^/]*)$ teams.php?league=$1&team=$2&year=$3&tab=$4 [L]
没有运气,但...有什么想法?
感谢
你需要做的检查,在它旧的URL与php
实际上是被要求通过对%{THE_REQUEST}
匹配,否则会永远重定向环路(例如用户进入team.php ,服务器重定向到团队,浏览器请求团队,服务器重写为teams.php,服务器看到“teams.php”并且重定向到团队,浏览器请求团队,服务器重写为teams.php等等)
RewriteEngine On
# redirect when the user actually requests for teams.php
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /teams\.php\?league=([^&]+)&team=([^&]+)&year=([^&]+)&tab=([^\ ]+)
RewriteRule ^teams\.php$ /teams/%1/%2/%3/%4? [R=301,L]
# internally rewrite any /teams/ URI
RewriteCond %{REQUEST_URI} !^(css|js|img)/
RewriteRule ^teams/([^/]*)/([^/]*)/([^/]*)/([^/]*)$ teams.php?league=$1&team=$2&year=$3&tab=$4 [L]
为什么我们需要!^(css | js | img)/如果我用你的语法来重定向像teams.php这样的文件,我应该复制/粘贴RewriteCond!^(css | js | img)每次,或在htaccess中足够一次。谢谢:) – webtech 2015-08-02 20:40:38
问问题的人不想重写css,js或img文件夹的请求 – 2015-08-02 20:49:39
我说得对,你想让任何点击“teams.php?league =。* ...”的人显示为“team/$ 1/...'? – 2012-07-24 12:53:29
是的,你是。 100%正确 – Lance 2012-07-24 15:16:34