简体   繁体   English

Apache .htaccess重定向到index.php不适用于子目录

[英]Apache .htaccess redirect to index.php not working for subdirectories

I'm working with the .htaccess file inside the website's main public directory. 我正在使用网站主要公共目录中的.htaccess文件。 I don't have access to php.ini or any other root operations (but can if necessary). 我无权访问php.ini或任何其他根操作(但如有必要,可以)。 I have a framework that is similar to wordpress in that I need all requests to go through index.php in the root directory. 我有一个类似于wordpress的框架,因为我需要所有请求都通过根目录中的index.php。 This works for the initial request (as it's just index.php), but any service or subdirectory request keeps returning a 404. 这适用于初始请求(因为它只是index.php),但是任何服务或子目录请求均会返回404。

This is my current .htaccess: 这是我当前的.htaccess:

<IfModule mod_rewrite.c>
RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule . /index.php [L]
</IfModule>

Can anyone please help solve this? 谁能帮忙解决这个问题?

Try this 尝试这个

<IfModule mod_rewrite.c>
RewriteEngine on 
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php [NC,L]
</IfModule>

If it doesn't solve, then Check if the mod_rewrite module is enabled on your server, You can check it using the following php function 如果不能解决,请检查服务器上是否启用了mod_rewrite模块,可以使用以下php函数进行检查

 <?php
 print_r(apache_get_modules());
  ?>

This function returns an array of all activated modules on the apache server. 此函数返回apache服务器上所有已激活模块的数组。

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

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