1

I have the following code in my htaccess file which is related to wordpress.

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

I created a new folder called test and when I try to access it from the browser, it shows a 404 error.

when I remove the code above from the htaccess file, I can access the new folder but the rest of the wordpress site breaks up. so I can't get rid of this code at all.

I tried adding this to the code:

RewriteCond %{REQUEST_URI} !^/test

so it looks like this:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/test
RewriteRule . /index.php [L]
</IfModule>

With no result and I still see the 404 error.

Could someone please advice on this issue?

I've tried many ways including this and still nothing works!!

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_URI}  !(test) [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Rooz Far
  • 187
  • 1
  • 3
  • 11
  • you mean you transfered a fiel – Vasim Shaikh May 01 '18 at 18:06
  • @VasimVanzara, I haven't moved or transferred anything! I simply created a folder directly from the cPanel. I also created test files (test.php and test.html) and I still get the 404 error when I try to access them form the browser. – Rooz Far May 01 '18 at 18:16

1 Answers1

0

How to move WordPress installation to sub folder

Move wp-*, index.php, .htaccess to your new wordpress folder Edit wordpress/.htaccess:

Find this line: RewriteRule . /index.php [L] Make it: RewriteRule . /wordpress/index.php [L] Create a new file in /path/to/www called .htaccess then add this:

RewriteEngine on
RewriteRule ^$ https://www.example.com/ [L]

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

Another way to do move all thing in sub directory

  • rename htaccess to backhtaccess.
  • Login to admin
  • Go settings -> permalinks-> save changes. All done.

=========================UPDATED ANSWER==============================

Add this line in your themes functions.php:

include(ABSPATH . 'custom.php');

Explanation:

Your wp-config.php should contain the following code (near the bottom of the page):

/** Absolute path to the WordPress directory. */
if ( !defined('ABSPATH') )
    define('ABSPATH', dirname(__FILE__) . '/');

They are saving the path to the wordpress installation to ABSPATH.

It will be something like "/var/www/foo/" or similar. So you can concat the ABSPATH with path to your file. If for example, your php file is located inside some folder like this "example.com/somefolder/custom.php" you would use

include(ABSPATH . 'somefolder/custom.php');

Hope this helps!

=======================Answer 3======================

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/(test/.*)$ 
</IfModule>

You can whitelist a folde using

RewriteCond %{REQUEST_URI} !^/(test|test/.*)$

Reference link :

.htaccess & Wordpress: Exclude folder from RewriteRule

Vasim Shaikh
  • 4,485
  • 2
  • 23
  • 52