This is my WP htaccess
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
I want wordpress' htaccess to stay out of the way when the link is to a standalone .html|.htm file inside the /ag directory.
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !/ag
RewriteRule . /index.php [L]
Doesn't work (I am aware the above code doesn't even try to implement the requirement that the file ends in .html|.htm). What do I need?
The original rewrite conditions only rewrite if the file does not exist, and is not a directory.
Therefore if you have the file in a directory, there should be no rewrite happening.
Wrong answers here. This thread helps:
non-wordpress files in wordpress installation directory
You need to specifically exclude the directory using rewrite rules, or Wordpress 3.4.1 won't allow access.
Related
I have a Wordpress installation in the root folder of my server and another Wordpress installation in a subfolder called "neueseite".
I can access the frontend of the page in the subfolder but not the admin area (backend). When I try to access it, it shows me a 404 error: https://paarkultur.ch/neueseite/wp-login.php
All URLs in the database contain the URL with the subfolder. I also tried different things with the .htaccess file. Nothing helped.
Here is the code inside the root directory's .htaccess file:
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
# Include in the next line all folders to exclude
RewriteCond %{REQUEST_URI} !(neueseite) [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
And this is the code in the subfolders .htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /neueseite/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /neueseite/index.php [L]
</IfModule>
Can someone help me figure out what the problem could be?
I checked your nginx server and the below file is not located in the directory listed below:
https://paarkultur.ch/neueseite/wp-login.php
I can see that you have various core files such as wp-config.php, readme.html, etc but you do not have wp-login.php in that directory.
Anyway if you are trying to serve multiple sites from a single server then you are going the wrong way about it
An default example file for a default Wordpress deployment is:
<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 have a special case scenario though where I have a subfolder as such in my root web directory that I need ignored:
/folderA/folderB/specialCase.php
I basically need:
/folderA/folderB/*
to be ignored, but I do need:
/folderA/folderB/specialCase.php
to be directly accessible and served.
The problem is that /folderA/folderB currently maps to a URI in my Wordpress install. Since the directories actually exist in the web root folder, currently Apache is serving up the index.php within /folderA/folderB/.
I need it to skip over these subfolders and continue processing URI mappings as usual, except in the special case where specialCase.php is requested?
Difficult? Hard? I'm stumped at the moment. Have been experimenting with the [PT] (passthrough) flags but no luck so far.
Thanks!
Couldn't you just check for that specific file, and serve it. Otherwise redirect the rest to the wordpress rules. Maybe something like this.
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/folderA/folderB/specialCase\.php$ [NC]
RewriteRule ^ - [L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_URI} ^/folderA/folderB/?$ [NC,OR]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
Also you could probably add another .htaccess in folderA/folderB/.htaccess with this
DirectoryIndex disabled
Which will also prevent it from serving index.php in that directory only.
I have a application that uses rewrite conditions, and then I added wordpress. I could not get /blog to rewrite properly.
Please see below for both HTACCESS files in root, and /blog (where wordpress is installed). I need to create a reference in root to allow /blog to work properly (im guessing). But how can I do this without breaking my other rewrite rules?
/.htaccess
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www.example.com$
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?sn=$1 [QSA,L]
#RewriteRule ^([a-zA-Z0-9/%-]+)$ index.php?sn=$1 [QSA]
Then in wordpress my wordpres install folder, i am simply doing:
/blog/.htaccess
#for blog directory only
RewriteEngine On
RewriteBase /blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
... and all other rw conditions needed for caching, etc
The reason the error was persistent with this dual HTACCESS setup was because the /blog/.htaccess file was missing an additional line:
RewriteRule . /blog/index.php [L]
Once added, it operated fine. No chances needed to go into the root htaccess to reference the /blog/ rewrite conditions. This allows for a wordpress install in a blog folder, and above references dual HTACESS rules
In my root .htaccess file I have the following Wordpress code:
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wordpress/index.php [L]
Slightly different to the standard code because the Wordpress files are in a "wordpress" directory but rewrites still appear relative to the domain root. For example a blog post can be called site.com/this-is-a-blog-post.php and the rewrite works.
This works great except when I want to use htpasswd to protect a directory on the site. If I add the following code to a .htaccess file in any directory I get a 404 when trying to browse to that directory:
AuthName "Private"
AuthUserFile "/home/passwd"
AuthType Basic
require valid-user
This code works correctly when the last line of the Wordpress rewrite code is commented out, but with the Wordpress code intact my password protected directory gives a 404.
So I have a conflict between the two .htaccess files somehow. I have tried writing a bunch of RewriteCond's to try and exclude the subdirectory with the password applied but can't nail it.
Ok, Murphy's Law, just worked it out after posting the question!
The extra condition needed for the Wordpress rewrite is:
RewriteCond %{REQUEST_URI} (/|\.htm|\.php|\.html|#.*|\?.*|/[^.]*)$ [NC]
So the complete Wordpress rewrite code becomes:
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (/|\.htm|\.php|\.html|#.*|\?.*|/[^.]*)$ [NC]
RewriteRule . /wordpress/index.php [L]
Now I'll go finish my humble pie.
I have the followind htaccess in my main root... but I want to exclude a subdomain folder to install a wordpress... actually the wordpress im trying to install is giving error ,, when I remove this htaccess the wordpress works fine... thanks
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
# Get rid of index.php
RewriteCond %{REQUEST_URI} /index\.php
RewriteRule (.*) index.php?rewrite=2 [L,QSA]
# Rewrite all directory-looking urls
RewriteCond %{REQUEST_URI} /$
RewriteRule (.*) index.php?rewrite=1 [L,QSA]
# Try to route missing files
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} public\/ [OR]
RewriteCond %{REQUEST_FILENAME} \.(jpg|gif|png|ico|flv|htm|html|php|css|js)$
RewriteRule . - [L]
# If the file doesn't exist, rewrite to index
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?rewrite=1 [L,QSA]
</IfModule>
To exclude a file from htaccess, you can place an htaccess file in the directory with a simple:
RewriteEngine On
Otherwise, in the root folder's htaccess file, you can add this right below the RewriteEngine On:
RewriteRule ^directory_you_want_to_protect - [L]
But I suspect that this is really a XY Problem here. You're probably going to need to rework or combine the htaccess rules that wordpress requires with the ones that you have right now. They may not be entirely compatible. If it's a matter not being able to run the installer, simply remove the root's htaccess file temporarily, install wordpress, then figure out how to combine the rules.