简体   繁体   中英

How to configure .htaccess for subdirectory

I have a WordPress site hosted on AWS and I am having a hard time to configure mod_rewrite to work correctly.

Folder structure

/root
  |_ staging/
  |_ live/

The .htaccess is the WordPress default

<IfModule mod_rewrite.c>

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

</IfModule>

Main Problem

I can access /staging/index.php/api which I used to access it without subdirectories like this ---.com/api .

When I try /staging/api it shows File not found .

I tried to change the .htaccess to different thing but none of them was successful.

There are no .htaccess file in the root directory.

Some help would be appreciated =)

Thanks in advance.

Try this code

<IfModule mod_rewrite.c>

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

</IfModule>

Note: The AllowOverride should be set to All in server configuration. You can find the reference from here. How to Set AllowOverride all

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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