如何使用htaccess更改URL结构? [英] How to change URL structure with htaccess?

查看:63
本文介绍了如何使用htaccess更改URL结构?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在 http://www.question2answer.org/ 的网站上下载并安装了该文件。 href = http://www.yourstartups.com/discussion/ rel = nofollow> http://www.yourstartups.com/discussion/ (讨论子目录)

I have downloaded and installed http://www.question2answer.org/ on my website on http://www.yourstartups.com/discussion/ (discussion sub-directory)

当前的网址结构如下:example.com/index.php?qa=123&qa_1=为什么做鸟唱
我想更改为/ 123 /为什么- do-birds-sing
(为什么是do-birds-sing是示例查询)

Current url structure is like: example.com/index.php?qa=123&qa_1=why-do-birds-sing I want to change to /123/why-do-birds-sing (why-do-birds-sing is example query)

以下是我的htaccess:

Following is my htaccess:

DirectoryIndex index.php
<IfModule mod_rewrite.c>
RewriteEngine On
#RewriteBase /
RewriteCond %{REQUEST_URI} ^(.*)//(.*)$
RewriteRule . %1/%2 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ index.php?qa-rewrite=$0&%{QUERY_STRING} [L]
</IfModule>

有人可以帮助我吗?

推荐答案

您需要一个新规则来重写漂亮的URL。

You need a new rule to rewrite your pretty URL.

DirectoryIndex index.php
<IfModule mod_rewrite.c>
RewriteEngine On
#RewriteBase /
RewriteCond %{REQUEST_URI} ^(.*)//(.*)$
RewriteRule . %1/%2 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)/?$ index.php?qa=$1&qa_1=$2 [L,QSA]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ index.php?qa-rewrite=$0 [L,QSA]
</IfModule>

这篇关于如何使用htaccess更改URL结构?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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