【问题标题】:Htaccess Rewrite for Multiple Optional Parameters多个可选参数的 Htaccess 重写
【发布时间】:2015-08-02 00:58:26
【问题描述】:

所以基本上我想要的是 Guild Hosting 网站,但我的 htaccess 不再工作了,这就是我想要的:

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

我打算让 PHP 处理网站是否有 WWW。或者不在使用 MySQL 数据库中的布尔集的网址开头,但现在我只想知道如何设置我的 .htaccess 文件以显示所有这样的站点并可能将它们重定向到正确的站点?这是我当前的.htaccess 文件:

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

我已经尝试寻找与此类似的不同东西,但我找不到特别像我的东西,所以有什么想法吗?

【问题讨论】:

    标签: php mysql .htaccess mod-rewrite


    【解决方案1】:

    因此,我查看了不同的示例,并在 .htaccess 上搞砸了,最终让它发挥了作用!

    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
    

    因此,如果其他人正在从事类似的项目,只需使用此代码即可,但您只需要使用 PHP 来处理所有页面和子域等。

    【讨论】:

      猜你喜欢
      • 2020-05-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-05
      • 1970-01-01
      • 2013-12-26
      相关资源
      最近更新 更多