[英].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
:
For users that visit mydomain.com
, the server should return the index.html
file from the root. 对于访问
mydomain.com
用户,服务器应从根目录返回index.html
文件。
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.