Unable to exclude directory from rewriting rules - wordpress

I tried to do this in many ways, but I really cannot exclude directory "progress" from wordpress rewriting rules in .htaccess. I found many solutions but none of them seems to be working.
.htaccess in root directory of wp contains:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
I tried to use
RewriteCond %{REQUEST_URI} !^/(progress/.*)$
and
RewriteRule ^progress($|/) - [L]
and
RewriteCond %{REQUEST_URI} !^/?(admin|progress)/
and I even tried to put Alias /progress /home/website/progress to httpd.conf but it still not working properly. Surely, mod_rewrite is installed and working, it redirects me to index.php that shows 404 error when I trying to access the directory...

From here.
#Change
RewriteRule . /index.php [L]
#to:
RewriteRule ./ /index.php [L]

Both of your attempts should work when used correctly. As the rules are tested sequentially, you need to put the exceptional case in front of your existing Wordpress rule:
RewriteRule ^progress($|/) - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
Or when using the additional condition (well ok, here the order of the conditions does not matter as they all have to be fulfilled):
RewriteCond %{REQUEST_URI} !^/(admin|progress)/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

Does the directory progress actually exist? What's inside it?
Where are you placing the code you have provided within the context of the .htaccess?
The line RewriteCond %{REQUEST_FILENAME} !-d will mean the rewrite rule is ignored if the request translates to a real directory.

Instead of following on .htaccess
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Use the folder name that you want to exclude from wordpress htaccess rule as RewriteBase, so basically try writing following in .htaccess file for the folder "FOLDER_NAME"
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /FOLDER_NAME
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
And place this .htaccess file into the folder with name "FOLDER_NAME". Please let me know if that works.

Related

wordpress htaccess file causes new files and folders to show 404 error?

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

htaccess redirection to particular folder

I have installed word press in the public html folder of my hosting. I have put my old codeigniter site files into "oldsite\codeigniter". But i am unable to access this code igniter website always getting page not found error from word press
Sample URL : example.com/oldsite/codeigniter
How can i redirect to sub folder if the URL contains "oldsite" or oldsite/codeigniter
RewriteEngine On
RewriteRule ^oldsite/codeigniter/(.*)$ example.com/oldsite/codeigniter/$1 [NC,R=301,L]
codeigniter htaccess file
RewriteEngine on
RewriteCond %{REQUEST_URI} !(.gif|.jpg|.png)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
RewriteRule codeigniter/home$
example.com/oldsite/codeigniter[L,R=301]
This should be a comment, but is a bit too long.
To reiterate the initial setup: Wordpress is installed in the document root, public_html. And there's an old CodeIgniter website, which is installed in public_html/oldsite/codeigniter.
There should be just two .htaccess files necessary, one for Wordpress and one for CodeIgniter. Both are taken from their respective websites, https://codex.wordpress.org/htaccess and https://codeigniter.com/user_guide/general/urls.html
# /public_html/.htaccess
# Wordpress
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# /public_html/oldsite/codeigniter
# CodeIgniter
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
If this fails for some reason, it might be that Apache is confused because of the relative path index.php. If this is the reason, you can fix it by using an absolute path, e.g.
RewriteRule ^(.*)$ /oldsite/codeigniter/index.php/$1 [L]
or add a RewriteBase directive
RewriteBase /oldsite/codeigniter

Load folder on specific Wordpress URL(category URL) with .htaccess

I'm trying to load the content(index.html) from specific folder on specific(already used URL) in Wordpress.
Here's the .htaccess file(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]
</IfModule>
# END WordPress
I've tried with few variations of this rewrite rule:
RewriteRule ^/category/funny-posts/ /funny-images/ [L]
So funny-images is a directory on my server where I have WP installed. Both of them are in the root folder.
How can I load index.html from /funny-images/ when I type www.site.com/category/funny-posts/ ?
If the index.html file is not displaying (and the URI you want is being passed to WP) it's probably because you're putting the rule at the end. Try putting it just after RewriteEngine On. Oh, and I don't think you'll need that RewriteBase. Also, you don't need that leading slash in the new rule, just before category.
Your file should now look like this:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^category/funny-posts/ /funny-images/ [L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

Add URL Rewrite Rule To Wordpress

I've written a Wordpress plugin that adds a query string to the URL. However I can't seem to modify the htaccess to rewrite this. Not sure if Wordpress is overriding it?
The current htaccess is:
# 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
And the URL I'm trying to rewrite is:
http://domain.com/deal-info/?id=87&post_name=testdealtitle
Desired URL:
http://domain.com/deal-info/87/testdealtitle
I've tried adding:
RewriteRule ^([^/]*)/([^/]*)$ /deal-info/?id=$1&post_name=$2 [L]
to no avail. Any ideas appreciated!
When you do this:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
This means: "if it's not a file, and if it's not a dir, redirect all incoming URLs to
index.php.
Your rewriterule should work... unless you've put it after the previous rewriterule. So, in short, are you sure your .htaccess it like that:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^([^/]*)/([^/]*)$ /deal-info/?id=$1&post_name=$2 [L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Please tell me if it works.
Moreover if you only want to redirect only deal-info, you should do something like (not tested):
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^(/)?deal-info/([^/]*)/([^/]*)$ /deal-info/?id=$2&post_name=$3 [L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Two hints:
Please try to use the RewriteLog directive: it helps you to track down such problems:
# Trace:
# (!) file gets big quickly, remove in prod environments:
RewriteLog "/web/logs/mywebsite.rewrite.log"
RewriteLogLevel 9
RewriteEngine On
My favorite tool to check for regexp:
http://www.quanetic.com/Regex (don't forget to choose ereg(POSIX) instead of preg(PCRE)!)
May I ask you to add the rewritelog in your question?
After much confusion I found an answer here:
https://wordpress.stackexchange.com/questions/5413/need-help-with-add-rewrite-rule
Though I think the proper way to do it is by:
http://codex.wordpress.org/Rewrite_API/add_rewrite_rule
I'm not sure if you can do this directly in htaccess, or I was having a conflict problem with another plugin I was using.
Thanks again to Olivier for his extensive answer!

Unable to ignore a directory in WordPress install via .htaccess

/custom/player-registration.php
I've used the following .htaccess in my WordPress install and I can't access the above URL... any tips? I've tried 2 methods here... The URL continues to go to a WordPress search page.
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^custom - [L,NC]
RewriteCond %{REQUEST_URI} !^/(custom|custom/.*)$
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
UPDATE
I suppose I need to clarify that I am able to access /custom but am NOT able to access files within that directory... how do I access files within that directory?
Default WP .htaccess:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
means: if request doesn't point to any existing file or directory, use index.php
So it should serve Your file well with default settings. What are You trying to acomplish with the rest of Your file?
Try
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^custom.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

Resources