.htaccess - 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]
有谁知道它可能是什么?好像我可以修复那条线那么这应该有望解决我的问题。
解决方案
好的,这是我们设法混合和匹配的最终结果,直到它起作用。
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]
推荐阅读
- c# - 如何使用 IEnumerable 作为导航属性而不是 IList
- kotlin - Kotlin 中 lambda 和 KFunction 的区别
- javascript - 我可以在方程式中使用 JS .offsetHeight 结果来设置子元素的样式吗?
- c# - 为什么将 .Wait() 添加到我的任务有时会允许任务使用主线程?
- javascript - ng2-dnd : 错误: StaticInjectorError(AppModule)[SortableComponent -> ElementRef]:
- azure - 多次触发带有队列的 Azure WebJob
- c# - WPF 中的编程数据绑定不起作用
- laravel - 返回数组 Api 资源对象时分页
- javascript - Highcharts,5个小图表,有些随机不画
- javascript - 将事件对象发送到没有 event.persist 的回调