douyan3478
douyan3478
2013-11-06 16:47

.htaccess重定向到index.html,如果有参数,则重定向到index.php

已采纳

I am looking for a .htaccess that does the following:

  1. For users that visit mydomain.com, the server should return the index.html file from the root.

  2. For users that visit mydomain.com/something/, mydomain.com/anything/123/, mydomain.com/some%20encoded%20text, etc., the server should return the index.php file from the root and pass the text after www.mydomain.com/ as a PHP $_GET variable.

I tried the WordPress .htaccess:

RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

But this redirects everything to the index.php file.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • douzi5214 douzi5214 8年前

    Enable mod_rewrite and .htaccess through httpd.conf (if not already enabled) and then put this code in your DOCUMENT_ROOT/.htaccess file:

    RewriteEngine On
    
    RewriteRule ^$ /index.html [L]
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.+)$ /index.php?f=$1 [L,QSA]
    

    Inside index.php you can access $_GET['f'] variable that will give you requested URI.

    点赞 评论 复制链接分享

相关推荐