duananyu9231 2015-08-02 00:58
浏览 33
已采纳

Htaccess重写多个可选参数

So essentially want I'm working on is Guild Hosting site but my htaccess isn't working anymore, here is what I want:

http://www.example.com/?page=test => http://www.example.com/test

http://www.example.com/?site=testsite => http://testsite.example.com or http://www.testsite.example.com
http://www.example.com/?site=testsite&page=test => http://testsite.example.com/test or http://www.testsite.example.com/test

I'm going to make it so PHP processes whether or not the site has a WWW. or not at the start of the web address using a boolean set in a MySQL Database but for now I just want to know how can setup my .htaccess file to display all the sites like this and possibly redirect them to the right ones? Here is my current .htaccess file:

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\. [OR]
RewriteCond %{HTTP_HOST} ^www\.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !index\.php
RewriteCond %{HTTP_HOST} ^(.+?)\.dev.randamonium.com$
RewriteRule ^([^/]+)/(.*)$ /index.php?site=%1&site=%2 [L]

<Files .htaccess>
order allow,deny
deny from all
</Files>

Options All -Indexes

I've tried looking for different things similar to this but I can't find ones specifically like mine so any ideas?

  • 写回答

1条回答 默认 最新

  • douxiajia6720 2015-08-02 04:30
    关注

    So I was looking at different examples and messing around with the .htaccess and ended up making it work!

    RewriteEngine On
    RewriteCond %{HTTP_HOST} !^www\. [OR]
    RewriteCond %{HTTP_HOST} ^www\. 
    RewriteCond %{REQUEST_URI} !index\.php
    RewriteCond %{HTTP_HOST} ^(.+?)\.dev.randamonium.com$
    RewriteRule ^([^/]*)/([^/]*)/?$ /index.php?site=%1&page=$2 [L]
    
    <Files .htaccess>
    order allow,deny
    deny from all
    </Files>
    
    Options All -Indexes
    

    So if anyone else is working on a similar project just use this code and it will work but you just need to use PHP to process all the pages and subdomains, etc.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler