.htaccess 重定向 URL,包含三个查询字符串


.htaccess redirect url with three query strings

我在.htaccess中有一些行,我正在尝试扁平化URL,但似乎我错过了一些东西。URL 被重定向,但在重定向 URL 时,大多数资源都"未找到"。

这是代码。

Options -Indexes +FollowSymLinks
RewriteEngine On
###########music#######
RewriteCond %{THE_REQUEST} ' /+profile'.php'?user=([^&]+)&title=([^&]+)&uid=([^&' ]+)
RewriteRule ^ /%1/%2/%3? [L,R=301]
RewriteCond %{THE_REQUEST} ' /+profile'.php'?user=([^&]+)&title=([^&' ]+)
RewriteRule ^ /%1/%2? [L,R=301]
#################internally redirect////////////
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)/([^/]+)$ profile.php?user=$1&title=$2&uid=$3 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)$ profile.php?user=$1&title=$2 [L,QSA]

我做错了什么?

看起来您已经遇到了人们在切换到漂亮的 URL 方案时面临的最常见问题。解决方案也很简单,只需在css,js,图像文件中使用绝对路径而不是相对路径即可。这意味着您必须确保这些文件的路径以http://或斜杠/开头。

您可以尝试在页面的 HTML 标头中添加以下内容:<base href="/" />以便从该 URL 而不是当前 URL 解析每个相对 URL。