dongshan8194 2014-08-26 13:19
浏览 44
已采纳

.htaccess在同一目录中重写多个URL

I want to rewrite some URL's but because i'm kind of a .htaccess noob, I have no idea how to make it myself.

So far I have: example(.)com/server/SERVERNAME that goes to example(.)com/server/index.php?server=SERVERNAME

For this I use:

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

But from this point i'm stuck. I want example(.)com/server/SERVERNAME/vote/ to go to example(.)com/server/vote.php?server=SERVERNAME

It may sound weird or confusing, but I have no idea if it's even possible or not. Any help would be appreciated.

  • 写回答

1条回答 默认 最新

  • dsxi70423 2014-08-26 13:30
    关注

    You seem to be missing RewriteEngine On and also you need more than 1 rule to check whether matching .php file exists in /server/.

    Place this rule in /server/.htaccess:

    RewriteEngine On
    
    RewriteBase /server/
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{DOCUMENT_ROOT}/server/$2\.php -f [NC]
    RewriteRule ^([^/]+)/([^/]+)/?$ $2.php?server=$1 [L,QSA]
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^([^/]+)/?$ index.php?server=$1 [L,QSA]
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 vue3加ant-design-vue无法渲染出页面
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 路易威登官网 里边的参数逆向
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
  • ¥50 需求一个up主付费课程
  • ¥20 模型在y分布之外的数据上预测能力不好如何解决
  • ¥15 processing提取音乐节奏
  • ¥15 gg加速器加速游戏时,提示不是x86架构
  • ¥15 python按要求编写程序