How to change URL structure with htaccess?

2019-09-15 17:32发布

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?

标签: .htaccess
1条回答
劳资没心,怎么记你
2楼-- · 2019-09-15 18:22

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>
查看更多
登录 后发表回答