Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.htaccess mod_重写配置,用于/_.htaccess_Mod Rewrite - Fatal编程技术网

.htaccess mod_重写配置,用于/

.htaccess mod_重写配置,用于/,.htaccess,mod-rewrite,.htaccess,Mod Rewrite,我有以下.htaccess配置 RewriteEngine On RewriteBase / RewriteCond %{HTTP_HOST} ^example.com [NC] RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301] RewriteRule \.git - [F,L] RewriteRule ^help help.php [L] RewriteRule ^home home.php [L] RewriteRule ^pr

我有以下
.htaccess
配置

RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
RewriteRule \.git - [F,L]

RewriteRule ^help help.php [L]
RewriteRule ^home home.php [L]
RewriteRule ^profile profile.php [L]
RewriteRule ^index index.php [L]

RewriteRule ^users/([0-9]+) profile.php?id=$1 [L]

RewriteRule ^([A-Za-z0-9-]+)?$ profile.php?u=$1 [L]
现在,每当有人访问登录页时,他们都会使用
profile.php?u=$1的最后一条规则重定向


如何更改配置,使
www.example.com
www.example.com/
映射到index.php而不是profile.php?

匹配紧跟
^index
规则之后的空字符串或单斜杠:

RewriteRule ^help help.php [L]
RewriteRule ^home home.php [L]
RewriteRule ^profile profile.php [L]
RewriteRule ^index index.php [L]
# Match root request with optional slash
RewriteRule ^/?$ index.php [L]

匹配紧跟在
^index
规则之后的空字符串或单斜杠:

RewriteRule ^help help.php [L]
RewriteRule ^home home.php [L]
RewriteRule ^profile profile.php [L]
RewriteRule ^index index.php [L]
# Match root request with optional slash
RewriteRule ^/?$ index.php [L]

我建议不要这样做

相反,只需使用此

<IfModule mod_rewrite.c> 
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
就像迈克尔建议的那样

如果您愿意,这里有一个简单的工具来测试您的规则


我建议不要这样做

相反,只需使用此

<IfModule mod_rewrite.c> 
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
就像迈克尔建议的那样

如果您愿意,这里有一个简单的工具来测试您的规则


遗憾的是,我只能在8分钟后接受答案。非常感谢!遗憾的是,我只能在8分钟后接受答案。非常感谢!