.htaccess Mod Rewrite将带有查询字符串的URL重定向到pretty URL

.htaccess Mod Rewrite将带有查询字符串的URL重定向到pretty URL,.htaccess,mod-rewrite,.htaccess,Mod Rewrite,在mod rewrite的帮助下,我成功地将我的URL从querystring中带有多个参数的丑陋URL更改为外观整洁的URL。然而,我的网站有很多url。我没有返回并编辑每个锚标记上的href属性,而是尝试在.htaccess文件中编写一个重定向函数,自动将旧url重定向到新url 在.htaccess文件中,我有以下内容: RewriteEngine On Redirect teams.php?league=$1&team=$2&year=$3&tab=$4 tea

在mod rewrite的帮助下,我成功地将我的URL从querystring中带有多个参数的丑陋URL更改为外观整洁的URL。然而,我的网站有很多url。我没有返回并编辑每个锚标记上的href属性,而是尝试在.htaccess文件中编写一个重定向函数,自动将旧url重定向到新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]
但是运气不好。。。有什么想法吗


谢谢

你需要做一个检查,通过匹配
%{the_REQUEST}
,确认里面有
php
的旧URL实际上正在被请求,否则它将永远重定向循环(例如,用户转到team.php,服务重定向到teams,浏览器请求teams,服务器重写为teams.php,服务器看到“teams.php”并重定向到团队、浏览器请求团队、服务器重写为teams.php等)


我说的对吗?你想让任何点击
teams.php的人显示为
teams/$1/..
?我们到底需要什么^(css | js | img)/如果我使用你的语法重定向许多文件,比如teams.php,我应该复制/粘贴重写吗^(css | js | img)每次,或者在htaccess中一次就足够了。谢谢:)提问者不想重写css、js或img文件夹的请求
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]