How to change URL structure with htaccess?

懵懂的女人 提交于 2020-01-17 04:45:05

问题


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

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)

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>

Can anyone help me?


回答1:


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>


来源:https://stackoverflow.com/questions/26303110/how-to-change-url-structure-with-htaccess

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!