首页 > 解决方案 > ht-access 如何重定向到论坛主题网址?

问题描述

我想知道如何使用 ht-access 重定向我的页面,如下所示 .com/?page=forums&topic=topic-name 要更改为 .com/forums/topic-name?

下面的规则重定向所有页面名称,例如 .com/forums 或 .com/polls,我目前用来获取我的页面到 .com/index.php?page=forums。

RewriteRule ^(.+)$ index.php?page=$1 [L]

我希望www.treyarder.com/home重定向到www.treyarder.com/index.php?page=home以及www.treyarder.com/forums/topic-name重定向到www.treyarder.com/index .php?page=forums&topic=主题名

我的主题在www.treyarder.com/index.php?page=forums&topic=topic-name

我的 ht-access 文件如下所示

RewriteEngine on   
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d    
RewriteRule ^(.+)$ index.php?page=$1 [L]

RewriteCond %{HTTP_HOST} \.com [NC]
RewriteCond %{REQUEST_URI}  !\.\w{2,4}$
RewriteCond %{REQUEST_URI} ^/([^/]*)/([^/]*)/?$ [NC]
RewriteRule ^(.*)$ index.php?page=%1&topic=%2 [L]

ErrorDocument 404 /index.php?pages=404
ErrorDocument 500 /index.php?pages=500

下面的行似乎有问题

RewriteCond %{REQUEST_URI} ^/([^/]*)/([^/]*)/?$ [NC]

有谁知道它可能是什么?好像我可以修复那条线那么这应该有望解决我的问题。

标签: .htaccessurlredirectmod-rewriteurl-rewriting

解决方案


好的,这是我们设法混合和匹配的最终结果,直到它起作用。

RewriteEngine on  

RewriteCond %{HTTP_HOST} \.com [NC]
RewriteCond %{REQUEST_URI}  !\.\w{2,4}$
RewriteCond %{REQUEST_URI} ^/([^/]*)/([^/]*)/?$ [NC]
RewriteRule ^(.*)$ index.php?page=%1&topic=%2 [L]
RewriteCond %{REQUEST_URI}  !\.\w{2,4}$
RewriteCond %{REQUEST_URI} ^/([^/]*)/?$ [NC]
RewriteRule ^(.*)$ index.php?page=%1 [L]

推荐阅读