【问题标题】:Htaccess for avoiding index.php?page= from URLHtaccess 用于避免来自 URL 的 index.php?page=
【发布时间】:2013-10-11 05:29:26
【问题描述】:

我的项目有 http://domain.com/index.php?page=home/contactushttp://domain.com/index.php?page=events/announcementdetails/80 等 URL。

我想避免给定 URL 中的 index.php?page= 和 80 之类的参数,并希望将 URL 更改为 http://domain.com/home/contactushttp://domain.com/events/announcementdetails。如何使用 htaccess 文件实现这一点。

【问题讨论】:

    标签: .htaccess


    【解决方案1】:

    尝试将此添加到文档根目录中的 htaccess 文件中:

    RewriteEngine On
    
    RewriteCond %{THE_REQUEST} \ /index\.php\?([^\ ]*)
    RewriteRule ^ /%1 [L,R=301]
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /index.php?$1 [L,QSA]
    

    【讨论】:

      【解决方案2】:

      通过httpd.conf 启用mod_rewrite.htaccess,然后将此代码放入您的DOCUMENT_ROOT/.htaccess 文件中:

      RewriteEngine On
      
      RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+index\.php\?page=([^\s&]+) [NC]
      RewriteRule ^ /%1? [R=301,L,NE]
      
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule ^(.+)$ /index.php?page=$1 [L,QSA]
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2020-07-02
        • 2014-10-03
        • 1970-01-01
        • 1970-01-01
        • 2012-03-16
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多