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 删除虚拟显示器驱动 删除所有 Xorg 配置文件 删除显示器缓存文件 重启系统 可是依旧无法退出虚拟显示器
  • ¥15 vscode程序一直报同样的错,如何解决?
  • ¥15 关于使用unity中遇到的问题
  • ¥15 开放世界如何写线性关卡的用例(类似原神)
  • ¥15 关于并联谐振电磁感应加热
  • ¥60 请查询全国几个煤炭大省近十年的煤炭铁路及公路的货物周转量
  • ¥15 请帮我看看我这道c语言题到底漏了哪种情况吧!
  • ¥66 如何制作支付宝扫码跳转到发红包界面
  • ¥15 pnpm 下载element-plus
  • ¥15 解决编写PyDracula时遇到的问题