重写并重定向到url

问题描述 投票:0回答:1

我有这些规则:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/?$ ./user/?user=$1 [QSA,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(profile/)([^/]+)/?$ ./$1?user=$2 [QSA,L]

当我写www.mydomain.com/user?user=myuser时显示www.mydomain.com/myuser的内容,当我写www.mydomain.com/profile?user=myuser时显示www.mydomain.com/profile/myuser的内容。

现在我想从www.mydomain.com/user?user=myuser重定向到www.mydomain.com/myuser,并从www.mydomain.com/profile?user=myuser重定向到www.mydomain.com/profile/myuser,无论谁拥有旧的查询链接。

RewriteCond %{QUERY_STRING} ^user=([.*]+)&?[.*]? [NC]
RewriteRule ^(.*)$ /$2/$1 [R=302,L]

为什么不起作用?

编辑:第一条规则有效,我的问题来自重定向到新页面

apache .htaccess url-rewriting static rules
1个回答
0
投票

我认为首先您应该检查.htaccess是否已启用尝试放入其中:

order deny,allow
deny from all

在刷新页面后,如果出现403错误.htaccess正常运行

我发现了:

https://help.dreamhost.com/hc/en-us/articles/215747748-How-can-I-redirect-and-rewrite-my-URLs-with-an-htaccess-file-

RewriteEngine On
RewriteRule ^([0-9]+).html /abc.php?id=$1 [QSA,L]

而且我看不到您参数上的任何文件扩展名。尝试使用jsut几行规则,然后尝试使其变得更复杂

© www.soinside.com 2019 - 2024. All rights reserved.