admin管理员组

文章数量:1134039

I have setup wordpress in the root directory and at the same level I have some other directories e.g named "sq".

Under sq there are subdirectories like first, second, ... under each subdirectory there is index.php file.

Problem is when I am accessing it is giving me 404 page of root wordpress.

I tried index.html instead of index.php and that is working. So index.php is not woking and I need php not html.

I have tried all the possible google solutions of updating .htaccess but nothing is working for me. e.g I have tried this

# Include in the next line all folders to exclude
RewriteCond %{REQUEST_URI}  !(sq|folder2|folder3) [NC]
RewriteCond %{REQUEST_URI} !^/(sq|mydir/.*)$
RewriteBase /sq/

my complete .htaccess is as

# BEGIN WordPress
<IfModule mod_rewrite.c>
ErrorDocument 401 default
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]

# Include in the next line all folders to exclude
RewriteCond %{REQUEST_URI}  !(sq|folder2|folder3) [NC]
RewriteCond %{REQUEST_URI} !^/(sq|mydir/.*)$
RewriteBase /sq/

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]


#----- START DAP -----
RewriteCond %{REQUEST_FILENAME} -f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} (.*)/wp-content/uploads/(.*) 
RewriteCond %{REQUEST_FILENAME} !(.*)(\.php|\.css|\.js|\.jpg|\.gif|\.png|\.txt|\.ico|\.jpeg)$ 
RewriteRule (.*) /dap/client/website/dapclient.php?dapref=%{REQUEST_URI}&plug=wp&%{QUERY_STRING}  [L] 
#----- END DAP -----

</IfModule>

# END WordPress

Please help guys.

Thanks.

I have setup wordpress in the root directory and at the same level I have some other directories e.g named "sq".

Under sq there are subdirectories like first, second, ... under each subdirectory there is index.php file.

Problem is when I am accessing http://example.com/sq/first it is giving me 404 page of root wordpress.

I tried index.html instead of index.php and that is working. So index.php is not woking and I need php not html.

I have tried all the possible google solutions of updating .htaccess but nothing is working for me. e.g I have tried this

# Include in the next line all folders to exclude
RewriteCond %{REQUEST_URI}  !(sq|folder2|folder3) [NC]
RewriteCond %{REQUEST_URI} !^/(sq|mydir/.*)$
RewriteBase /sq/

my complete .htaccess is as

# BEGIN WordPress
<IfModule mod_rewrite.c>
ErrorDocument 401 default
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]

# Include in the next line all folders to exclude
RewriteCond %{REQUEST_URI}  !(sq|folder2|folder3) [NC]
RewriteCond %{REQUEST_URI} !^/(sq|mydir/.*)$
RewriteBase /sq/

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]


#----- START DAP -----
RewriteCond %{REQUEST_FILENAME} -f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} (.*)/wp-content/uploads/(.*) 
RewriteCond %{REQUEST_FILENAME} !(.*)(\.php|\.css|\.js|\.jpg|\.gif|\.png|\.txt|\.ico|\.jpeg)$ 
RewriteRule (.*) /dap/client/website/dapclient.php?dapref=%{REQUEST_URI}&plug=wp&%{QUERY_STRING}  [L] 
#----- END DAP -----

</IfModule>

# END WordPress

Please help guys.

Thanks.

Share Improve this question edited Jan 1, 2018 at 9:31 Bhuvnesh Gupta asked Jan 1, 2018 at 8:27 Bhuvnesh GuptaBhuvnesh Gupta 3112 gold badges9 silver badges20 bronze badges 2
  • 1 What does your complete .htaccess look like? – janh Commented Jan 1, 2018 at 8:59
  • @janh I have updated my code – Bhuvnesh Gupta Commented Jan 1, 2018 at 9:30
Add a comment  | 

1 Answer 1

Reset to default 1

All you should need to do is make sure the appropriate DirectoryIndex is set. For example, at the top of your .htaccess file:

DirectoryIndex index.php

This instructs mod_dir to try to serve index.php when requesting a directory, eg. /sq/first/.

If you are requesting URLs/directories that don't already contain the trailing slash, as in your example: /sq/first, then you need to make sure that DirectorySlash On (also part of mod_dir) is also set (although this is the default setting). For example:

DirectoryIndex index.php
DirectorySlash On

However, you should really be requesting the /sq/first/ (with a trailing slash), as otherwise mod_dir issues a 301 redirect in order to append the trailing slash - which is an additional round trip to your server.


RewriteBase /
:
RewriteBase /sq/

Aside: Ideally, you should never include more that one RewriteBase directive in your .htaccess file. Since WordPress is installed in the document root, then RewriteBase should probably be set to the document root, ie. RewriteBase /. If you have more than one RewriteBase directive then the last one wins and controls the entire file. So, in this example, RewriteBase is set to /sq/, not /. However, in your .htaccess file, RewriteBase is not actually being used anyway. (You also have it in the middle of a rule block - which doesn't make much sense - in fact, I'm surprised that doesn't result in an error?)


UPDATE: So, in summary:

DirectoryIndex index.php
DirectorySlash On

ErrorDocument 401 default

# 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]    

#----- START DAP -----
RewriteCond %{REQUEST_FILENAME} -f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} (.*)/wp-content/uploads/(.*) 
RewriteCond %{REQUEST_FILENAME} !(.*)(\.php|\.css|\.js|\.jpg|\.gif|\.png|\.txt|\.ico|\.jpeg)$ 
RewriteRule (.*) /dap/client/website/dapclient.php?dapref=%{REQUEST_URI}&plug=wp&%{QUERY_STRING}  [L] 
#----- END DAP -----

</IfModule>
# END WordPress

You should avoid adding your own custom code between the # BEGIN WordPress and # END WordPress comment markers as WP itself might overwrite this in a future update.

I removed the section you had to "exclude" certain directories. That shouldn't do any harm, however, it is also unnecessary, given the existing WordPress mod_rewrite directives. WordPress (the mod_rewrite directives above) already excludes physical directories from being routed through WP.

本文标签: url rewritingsubdirectory indexphp is not working