Good morning,
I have a very strange issue with the default .htaccess with WordPress.
I have a "stats" folder in the webroot which contain something else than WordPress. Usually, I can access it by doing www.example.com/stats/ on the web browser. But with one WordPress, www.example.com/stats/ is rewrited to the index.php of WordPress.
Please note that I use the defaut WordPress .htaccess which 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>
Usually, RewriteCond %{REQUEST_FILENAME} !-d should help to skip rewriting as stats is a directory. But stats still rewrite to index.php.
I already tried to add some other RewriteCond (with REQUEST_FILENAME and QUERY_STRING) to try skipping manually stats directory but it not works. Here are them (as requested on comments):
RewriteCond %{REQUEST_FILENAME} !^stats$
RewriteCond %{REQUEST_FILENAME} !^stats/$
RewriteCond %{REQUEST_FILENAME} !^/stats/$
RewriteCond %{QUERY_STRING} !stats
RewriteCond %{QUERY_STRING} !^stats/$
RewriteCond %{QUERY_STRING} !^/stats/$
RewriteCond %{QUERY_STRING} !stats(.*)
Both are not working.
As requested in comment also, I tried to rename stats to another name. And it works with the name stats2. But I still want to use stats as folder name.
Note that it is not a caching issue.
Inside the folder stats, there is a .htaccess:
AuthType Basic
AuthName "Members Only"
AuthUserFile /var/www/clients/client0/web1/web/stats/.htpasswd_stats
require valid-user
Note that the folder stats is managed by ISPConfig.
Any idea to check? Thanks in advance.
Found the issue!!!
In general, Apache does the rewrite phase before the authorization phase, which is why your code performs the rewrite without ever asking for user to authenticate.
https://stackoverflow.com/a/13295036/7664726
I had to add it to the .htaccess in the website root:
RewriteCond %{LA-U:REMOTE_USER} !^$
So my final .htaccess is this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{LA-U:REMOTE_USER} !^$
RewriteRule . /index.php [L]
</IfModule>
Thanks to add peoples in comment section helping me solve this issue.
Instead of modifying the root .htaccess file, it may be preferable to simply disable the rewrite engine in the /stats/.htaccess file. Since mod_rewrite is not inherited (by default) this should prevent the WordPress front-controller in the root .htaccess file being processed.
For example, in /stats/.htaccess:
RewriteEngine Off
AuthType Basic
: etc.
Related
In /public_html/ I have a wordpress install as well as a directory - 'mydirectory' - that I'd like to protect and be able to access directly. I've got the protection setup with an .htaccess and .htpasswd file, but I'm only getting 404 errors when I try to access the files in that folder. I've tried just about every re-write option I can find for the root level .htaccess file, but nothing has worked. I'm curious if I'm missing something outside of the rewrite condition that could be affecting it? I cannot seem to figure out why I can't get this to work! Below are my various .htaccess files and the rewrites i've tried.
Root Level:
# 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>
# END WordPress
.htaccess in mydirectory:
ErrorDocument 401 default
AuthType Basic
AuthName "LampreyTrillo"
AuthUserFile file:///public_html/mydirectory/.htpasswd
Require valid-user
.htpasswd in mydirectory:
test:pass
Rewrites I've Tried:
RewriteRule ^mydirectory(/.*)?$ - [L,NC]
# disable the rewrite engine in the ignored directory .htaccess
RewriteEngine off
RewriteCond %{REQUEST_URI} ^/mydirectory/(.*)$
RewriteCond %{REQUEST_URI} !(mydirectory) [NC]
#Change last rewrite rule from '. /index.php' to './ /index.php'
RewriteRule ^mydirectory/.*$ - [PT]
RewriteCond %{REQUEST_URI} !^/(mydirectory|mydirectory/.*)$
I'm stumped, cant figure out what I'm missing here so any advice or new information would be greatly appreciated! Thank you in advance!
Add this to your .htaccess file:
RewriteCond %{REQUEST_URI} !(your_excluded_directory|your_excluded_directory_2|your_excluded_directory_3_etc) [NC]
just before
RewriteCond %{REQUEST_FILENAME} !-f
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 vbulletin with vbseo installed and the .htaccess code is
# Comment the following line (add '#' at the beginning)
# to disable mod_rewrite functions.
# Please note: you still need to disable the hack in
# the vBSEO control panel to stop url rewrites.
RewriteEngine On
# Some servers require the Rewritebase directive to be
# enabled (remove '#' at the beginning to activate)
# Please note: when enabled, you must include the path
# to your root vB folder (i.e. RewriteBase /forums/)
#RewriteBase /
#RewriteCond %{HTTP_HOST} !^www\.yourdomain\.com
#RewriteRule (.*) http://www.yourdomain.com/forums/$1 [L,R=301]
RewriteRule ^((urllist|sitemap_).*\.(xml|txt)(\.gz)?)$ vbseo_sitemap/vbseo_getsitemap.php?sitemap=$1 [L]
RewriteCond %{REQUEST_URI} !(admincp/|modcp/|cron|vbseo_sitemap|api\.php)
RewriteRule ^((archive/)?(.*\.php(/.*)?))$ vbseo.php [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !/(admincp|modcp|clientscript|cpstyles|images)/
RewriteRule ^(.+)$ vbseo.php [L,QSA]
the sub-domains have wordpress on it for example : games.domain.com not working it gives me Internal Server Error
so how to resolve this issue? and get's the domain and sub-domains work ?
I solve the problem by adding .htaccess file into games folder with the following code only
RewriteEngine Off
I was digging the net and haven't found any proper solution for this issue. Basically, I want to remove subdirectory (subdirname) name from all URLs, e.g.:
http://test.com/subdirname/
http://test.com/subdirname/content/
http://test.com/subdirname/content/newpage
The website is based on Wordpress and located in /subdirname. I've got two .htaccess files, one in root directory:
# Turn on URL rewriting
RewriteEngine On
# Installation directory
RewriteBase /
# Protect hidden files from being viewed
<Files .*>
Order Deny,Allow
Deny From All
</Files>
# Protect application and system files from being viewed
RewriteRule ^(?:application|modules|system)\b.* index.php/$0 [L]
# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
#RewriteCond %{REQUEST_URI} !^(/var|/static)
#RewriteCond %{REQUEST_URI} !^(/index\.php|/var|/static)
# Rewrite all other URLs to index.php/URL
RewriteRule .* index.php/$0 [PT]
RewriteCond %{HTTP_HOST} ^(www\.)?test\.com$ [NC]
RewriteCond %{REQUEST_FILENAME} !/subdirname/
RewriteRule ^(.*)$ /subdirname/$1 [L]
and second in /subdirname/ directory:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /subdirname/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /subdirname/index.php [L]
</IfModule>
# END WordPress
If anyone has some tips how to solve it, please advice.
You should be able to set up WordPress to display at your root domain but be installed in the subdirectory. Just change ONLY the site URL under the Settings-> General screen. Leave the subdirectory in the WordPress URL box. Then you would login at http://yoursite.com/subdirectory/wp-admin, but folks visit your site at http://yoursite.com.
I'm trying to combine the following code so that the WordPress permalinks work in the main directory, waringis.com (top code) and a second domain, burrowpress.com, is redirected to the subdirectory 'waringis.com/burrowpress' (bottom code) -
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
RewriteEngine On
RewriteCond %{HTTP_HOST} burrowpress.com$ [NC]
RewriteCond %{REQUEST_URI} !^/burrowpress/.*$
RewriteRule ^(.*)$ /burrowpress/$1
Right now permalinks are working in WordPress and the redirect works but images have to be direct links to waringis.com/burrowpress/images/ instead of burrowpress.com/images/ - Any help is much appreciated...
You need to swap your code blocks around. The [L] flag on the WordPress rules are stopping execution of the file at that line in their code since your special path would "pass" the WordPress REWRITE_COND statements:
RewriteEngine On
RewriteCond %{HTTP_HOST} burrowpress.com$ [NC]
RewriteCond %{REQUEST_URI} !^/burrowpress/.*$
RewriteRule ^(.*)$ /burrowpress/$1 [L]
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
You don't need two RewriteEngine On statements, but since WordPress is able to rewrite your .htaccess file (depending on how you have it setup) you might want to leave it. If you are updating your file manually, you can remove the second RewriteEngine on directive.
The important part is that I moved your special rules ahead of wordpress.
I'm not a .htaccess expert but i would say that you don't need to include RewriteEngine On twice that you can put the redirect code in the if statement. So you want to redirect to the subdomain but not have your images be kept in the subdomain is this correct?