我需要它处理所有的html URL(索引除外),我尝试使用.htaccess没有运气。
例如..。将此链接从:http://www.example.com/signup.html更改为http://www.example.com/?c=signup。
另外,如果我直接输入http://www.example.com/?c=signup,它必须镜像http://www.example.com/signup.html。
编辑我找到了这样做的方法,除了我直接输入到.html文件的情况之外,在这种情况下,它不会重写。
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteCond %{QUERY_STRING} ^c=([^&]+) [NC]
RewriteRule ^/?$ %1.html [NC,L,QSA]发布于 2018-11-13 17:18:35
RewriteRule ^/?$ 1.html NC,L,QSA
要将(大概是指“重定向”,而不是“重写”)从signup.html重定向到/?c=signup,您可以在现有重写之前执行如下操作:
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ([^.]+)\.html$ /?c=$1 [R,L]当您的现有指令重写到REDIRECT_STATUS文件时,检查.html环境变量的条件会阻止重定向循环。
注意,这是一个临时的(302)重定向。如果这是永久性的,则将R更改为R=301,但只有在您确认它正常工作之后才会这样做。
你现有的指令可以整理一下,总之:
Options +FollowSymLinks -MultiViews
RewriteEngine On
# Redirect from signup.html to /?c=signup
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ([^.]+)\.html$ /?c=$1 [R,L]
# Rewrite from /?c=signup to signup.html
RewriteCond %{QUERY_STRING} ^c=([^&]+)
RewriteRule ^/?$ %1.html [QSD,L]想必,您希望从重写的替换中丢弃c=查询字符串。
https://stackoverflow.com/questions/53283909
复制相似问题