简体   繁体   English

.htaccess重定向到index.html或index.php(如果有参数的话)

[英].htaccess that redirects to index.html, or to index.php if there are parameters

I am looking for a .htaccess that does the following: 我正在寻找执行以下操作的.htaccess

  1. For users that visit mydomain.com , the server should return the index.html file from the root. 对于访问mydomain.com用户,服务器应从根目录返回index.html文件。

  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. 对于参观用户mydomain.com/something/mydomain.com/anything/123/mydomain.com/some%20encoded%20text等,服务器应返回index.php从根文件后通过文www.mydomain.com/作为PHP $_GET变量。

I tried the WordPress .htaccess : 我尝试了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. 但这会将所有内容重定向到index.php文件。

Enable mod_rewrite and .htaccess through httpd.conf (if not already enabled) and then put this code in your DOCUMENT_ROOT/.htaccess file: 通过httpd.conf启用mod_rewrite.htaccess (如果尚未启用),然后将此代码放入DOCUMENT_ROOT/.htaccess文件中:

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. index.php您可以访问$_GET['f']变量,该变量将提供您请求的URI。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM