.htaccess 将变量重定向到友好链接 - 许多重定向 [英] .htaccess redirect variable to friendly link - many redirects

查看:58
本文介绍了.htaccess 将变量重定向到友好链接 - 许多重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 htaccess 重定向变量以清理 url 时遇到问题.

I have a problem with htaccess redirecting a variable to clean url.

代码:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) index.php?page=$1 [R]

RewriteCond %{QUERY_STRING} ^page=about$ 
RewriteRule ^(.*)$ https://www.url.com/about? [R=301,L]

我只想将这个:?page=about"重定向到这个:/about"

i just want to redirect this: "?page=about" to this: "/about"

上面的代码给了我很多重定向...

and with the code above give me to many redirects...

感谢您花时间看这个.

推荐答案

这是完整的代码.

#Rewrite settings
Options +FollowSymlinks
RewriteEngine on

RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

RewriteCond %{HTTP_HOST} ^url.com [NC]
RewriteRule ^(.*)$ https://www.url.com/$1 [L,R=301]

#Remove index.php from url
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(.*)index\.php($|\ |\?)
RewriteRule ^ /%1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)$ index.php?p=$1 [L]

#RewriteCond %{QUERY_STRING} ^p=about$ 
#RewriteRule ^(.*)$ https://www.url.com/about? [R=301,L]

RewriteCond %{HTTP_USER_AGENT} libwww-perl.* 
RewriteRule .* ? [F,L]

这段代码被注释了,因为这样不起作用:

This piece of code is commented because like this does not work:

#RewriteCond %{QUERY_STRING} ^p=about$ 
#RewriteRule ^(.*)$ https://www.url.com/about? [R=301,L]

这篇关于.htaccess 将变量重定向到友好链接 - 许多重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆