的.htaccess转换查询字符串永远不会奏效 [英] .htaccess to convert query string never works

查看:91
本文介绍了的.htaccess转换查询字符串永远不会奏效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目标: 为了有一个查询字符串转换成一个好看的URL,这是我从来没有得到工作。

的细节: 更改此网址: <$c$c>http://www.mywebsite.com/static-directory/index.php?state=florida&city=tallahassee

这一个: http://www.mywebsite.com/static-directory/florida/tallahassee

我曾尝试: 好了,刚才的一切。我最近的搜索想出了这个教程 ......

我有我的的.htaccess 文件在我的根目录下(httpdocs资料)。

任何帮助或点我在上堆栈溢出的正确回答的问题。

感谢。

解决方案
  

问:
  更改此网址:<?code> ... /静态目录/ index.php的状态=佛罗里达州和放大器;城市=塔拉哈西   
这一个: ... /静态目录/佛罗里达/塔拉哈西

据的问题,所有需要的是转换的第一URL(该请求)与查询的第二一个没有一个查询。

下面是一个的方式来实现,在一个.htaccess文件的根目录下:

 选项+了FollowSymLinks -MultiViews
RewriteEngine叙述上
的RewriteBase /

的RewriteCond%{} THE_REQUEST /static-directory/index.php\?state=([^&]+)&city=([^\s&]+)[NC]
重写规则^静态目录/ index.php文件/静态目录/ 1%/ 2%? [R = 301,L,NC]
 

然而,就在万一OP忘记提到的整体思路是消除查询,以便有一个pretty的网址,但仍从原来的URL获取数据,加上未来2行的规则集:

 的RewriteCond%{REQUEST_URI}!指数\ .PHP [NC]
重写规则^静态目录/([^ /] +)/([^ /] +)/static-directory/index.php?state=$1&city=$2 [L]
 

The goal: To have a query string converted into a nice looking URL, which I have never gotten to work.

The details: Change this URL: http://www.mywebsite.com/static-directory/index.php?state=florida&city=tallahassee

to this one: http://www.mywebsite.com/static-directory/florida/tallahassee

What I have tried: Well, just about everything. My latest search came up with this tutorial...

I have my .htaccess file in my root directory (httpdocs).

Any help or point me at the right answered question on Stack Overflow.

Thanks.

解决方案

QUESTION:
"Change this URL: .../static-directory/index.php?state=florida&city=tallahassee
to this one: .../static-directory/florida/tallahassee"

According to the question, all is needed is to convert the 1st URL (The Request) with the query to the 2nd one without a query.

Here is a way to achieve that in one .htaccess file at root directory:

Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteBase /

RewriteCond %{THE_REQUEST} /static-directory/index.php\?state=([^&]+)&city=([^\s&]+) [NC]
RewriteRule  ^static-directory/index.php  /static-directory/%1/%2? [R=301,L,NC]

However, just in in case the OP forgot to mention the whole idea is to remove the query in order to have a "pretty" URL but still get the data from the original URL, add next 2 lines to the rule-set:

RewriteCond %{REQUEST_URI}  !index\.php [NC]
RewriteRule  ^static-directory/([^/]+)/([^/]+) /static-directory/index.php?state=$1&city=$2 [L]

这篇关于的.htaccess转换查询字符串永远不会奏效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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