rewritecond exclude url in .htaccess - wordpress

I have these working rewrite rules :
# Allow access to assets folder from plugins folders
RewriteRule ^app/plugins/(.+)/assets - [L]
# forbid access to files and folders under app
RewriteRule ^app/.*$ - [L,F]
# rewrite to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?action=$1 [L,QSA]
Now I would like to exclude from these rules everything located under http://www.mywebsite.com/wordpress/...
Therefore I've added a new rewrite condition :
...
# rewrite to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^\/wordpress\/ [NC]
RewriteRule ^(.*)$ index.php?action=$1 [L,QSA]
But it dosen't work. When I try to access something like this :
http://www.mywebsite.com/wordpress/contact-us/
it redirects me to index.php...
Any help would be really appreciated.

Ok I finally found what was going wrong with all of this :
In fact I did not notice that a .htaccess file was present in my /wordpress directory.
So on the .htaccess of my root directory I've added this rule on top of all the others :
RewriteRule ^wordpress - [L]
Then in the .htaccess of the wordpress directory I've these rules :
RewriteBase /wordpress/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wordpress/index.php [L]
I don't know if everything is optimized but it works !

Related

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

301 Redirect to subfolder but with input

I want my wordpress site redirections to remember the url but place it in a subfolder.
So http://www.example.com/test123 has to redirect to http://www.example.com/voetbal/test123
And http://www.example.com/0239 to http://www.example.com/voetbal/0239
My htaccess looks like this.
RewriteEngine On
RewriteBase /voetbal/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /voetbal/index.php [R=301, L]
this makes my site go from http://www.example.com to http://www.example.com/voetbal/
but only the root.
How can i make my htaccess to remember peoples input and place it after the /voetbal/
Try :
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ /voetbal%{REQUEST_URI} [L,R=301]

.htaccesss RewriteCond %{REQUEST_FILENAME} !-d does not work

I want to install WordPress in subdirectory and remove index.php in permalinks.
The server is IIS 6.0, support rewrite.
My webserver has the following directories:
webroot
--wp [wordpress folder]
webroot/.htaccess
RewriteCond %{HTTP_HOST} ^(www\.)?a.luckyet\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/wp/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /wp/$1
RewriteCond %{HTTP_HOST} ^(www\.)?a.luckyet\.com$ [NC]
RewriteRule ^(/)?$ wp/
webroot/wp/.htaccess
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f #1
RewriteCond %{REQUEST_FILENAME} !-d #2
RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L] #3
It works when I visit a.luckyet.com and a.luckyet.com/hello-world.html
But it does not work when I visit a.luckyet.com/wp-login.php or a.luckyet.com/wp-admin
The #3 works fine, but #1 and #2 can not work properly. Then I saw here and change the content of webroot/wp/.htaccess to:
RewriteEngine on
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]
It still does not take effect. Can anyone help me? Thanks in advance!
Update:
ISAPI_Rewrite version is 3.0.
All code in webroot/.htaccess:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?a.luckyet\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/wp/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /wp/$1
RewriteCond %{HTTP_HOST} ^(www\.)?a.luckyet\.com$ [NC]
RewriteRule ^(/)?$ wp/
All code in webroot/wp/.htaccess:
RewriteEngine on
# For file-based wordpress content (i.e. theme), admin, etc.
RewriteRule wp-(.*) wp-$1 [L]
# For normal wordpress content, via index.php
RewriteRule ^/$ index.php [L]
RewriteCond %{REQUEST_FILENAME} !-f #1
RewriteCond %{REQUEST_FILENAME} !-d #2
RewriteRule (.*) index.php/$1 [L]
Wordpress permalink is:
/%postname%.html
Thus, Wordpress can work fine when visit http://a.luckyet.com/ or http://a.luckyet.com/hello-world.html
Question:
If there is a real file like a.html in webroot/wp/, like webroot/wp/a.html, wordpress 404 error will be reported when visit http://a.luckyet.com/a.html, . How can I fixed this?
You're dynamically rewriting the URLs with the .htaccess file and WordPress settings to tack on the .html extension - any files that are "real-life" .html files are being handled upstream by the IIS Handler Mappings.
You'll have to update your Handler Mappings in IIS for .html files especially to direct the requests directly to the physical file.

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

Unable to exclude directory from rewriting rules

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.

Resources