带和不带查询字符串htaccess的URL重写 [英] htaccess URL Rewrite with and without query string

查看:143
本文介绍了带和不带查询字符串htaccess的URL重写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图重写某些URL,但我newbness的凑了过来。

I'm trying to rewrite some urls but my newbness is getting in the way.

网址输入到地址栏

example.com/prefix-suffix.html
example.com/prefix-suffix.html?v=huzzah

所需的输出(想他们显示等)

Desired output (would like them displayed like)

example.com/prefix/suffix/
example.com/prefix/suffix/huzzah

我已经看了一些其他的例子<一href="http://stackoverflow.com/questions/21892542/customize-url-or-hide-query-string-using-htaccess">like这一个,但我只是不明白他们在做什么,究竟还是怎么相当,这使得它具有挑战性的修改。

I've looked at a few other examples like this one, but I just don't understand what they are doing exactly or how rather, which makes it challenging to modify.

如果你有时间来解释每一行正在做我会的大大的AP preciate吧。

If you have the time to explain what each line is doing I would greatly appreciate it.

感谢。

推荐答案

您可以在 DOCUMENT_ROOT /的.htaccess 文件中使用此code:

You can use this code in your DOCUMENT_ROOT/.htaccess file:

RewriteEngine On
RewriteBase /

RewriteCond %{THE_REQUEST} \s/+([^-]+)-([^.]+)\.html\s [NC]
RewriteRule ^ /%1/%2/ [R=302,L,NE]

RewriteCond %{THE_REQUEST} \s/+([^-]+)-([^.]+)\.html\?v=([^\s&]+) [NC]
RewriteRule ^ /%1/%2/%3? [R=302,L,NE]

RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]

RewriteRule ^([^/]+)/([^/]+)/?$ /$1-$2.html [L]

RewriteRule ^([^/]+)/([^/]+)/([^/]+)/?$ /$1-$2.html?v=$3 [L,QSA]

这篇关于带和不带查询字符串htaccess的URL重写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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