Rewrite rule for everything except a folder - wordpress

I have an application that uses Zend Framework but has a WordPress blog under the public directory (folder is named "blog").
Accessing the blog's homepage is fine, but when I try to access the posts, my htaccess rules have it go through Zend Framework. What do I need to modify in my /public/.htaccess file to have it ignore requests to the /public/blog directory?
Here's the current .htaccess file:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
Thanks!

I think, this should work
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/public/blog/
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]

Related

.htaccess url redirect with exception

I have the following rule in my htaccess. It redirects the root URL and any unfound urls/files to my Wordpress installation (subfolder).
How can I create an exception rule so that if the URI begins with /staging/ the rule doesn't apply?
# REDIRECT TO THE WP FOLDER IF FILE REQUESTED DOESNT EXIST
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.+) - [PT]
RewriteRule (.*) /livesite/$1 [L]
Hope the question is clear.
Exception rule would be RewriteCond %{REQUEST_URI} !^/staging/
Hope I got it correctly
# REDIRECT TO THE WP FOLDER IF FILE REQUESTED DOESNT EXIST
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteCond %{REQUEST_URI} !^/staging/
RewriteRule ^(.+) - [PT]
RewriteRule (.*) /livesite/$1 [L]

How to bypass wordpress htaccess

The public_html folder contains a wordpress site. I have put a new Angular app in a subfolder called myapp.
so www.domain.com -> wordpress
and wwww.domain.com/myapp -> angular app
Now, if i refresh or try to access an url path (route) in angular, i get the 404 page of the wordpress site.
so the root (public_html) folder have an .htaccess like this :
# 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
In myapp folder (angular) i have this one :
RewriteEngine on
RewriteBase /myapp/
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^(.*) /index.html [NC,L]
Whatever i tries, it always end up as : everything in myapp works ok, (refresh, direct url access etc) BUT the www.domain.com -> myapp!!!
Or
www.domain.com still -> wordpress
But
My angular app give me 404 on refresh and direct url access!
This is my .htaccess i consider should works
RewriteEngine on
RewriteBase /
# Condition to get in my angular app
RewriteCond %{REQUEST_URI} ^/myapp/.*$
RewriteRule ^.*$ - [NC,L]
RewriteRule ^(.*) /myapp/index.html [NC,L]
#Condition to go in wordpress
RewriteCond %{REQUEST_URI} !^/myapp/.*$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
please help!!
Finally!!! it worked!!!
Lesson learned!!! dont try to mix .htaccess of different folders!!
The wordpress .htaccess didnt need any changes.
The Angular one (subfolder) changed like this :
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^(.*) index.html [NC,L]
So basically 2 things!!!
Removed the RewriteBase /myapp/
Removed the / in RewriteRule ^(.*) index.html [NC,L]
Hope this will help someone else ;-)

How do I pass control to another .htaccess file for all paths beneath a directory?

My site ww.example.com runs WordPress in its root directory, meaning that any paths are redirected to the WordPress install to be evaluated. I also have an install of DokuWiki under www.example.com/path/to/wiki/, which similarly uses .htaccess to deliver wiki pages at paths like www.example.com/path/to/wiki/wikipage.
The file structure on the server stores all the non-WordPress content in a subdirectory called content, so the Dokuwiki install is actually located in content/path/to/wiki/.
Unfortunately, whilst www.example.com/path/to/wiki/ displays correctly, www.example.com/path/to/wiki/wikipage is clearly passed back to the top-level WordPress .htaccess and returns a 404 error.
What do I need in my .htaccess files to make this set-up work?
Example .htaccess files
Top-level WordPress .htaccess
# Rewrite to content directory
RewriteCond %{DOCUMENT_ROOT}/content/$1 -f [OR]
RewriteCond %{DOCUMENT_ROOT}/content/$1index.php -f [OR]
RewriteCond %{DOCUMENT_ROOT}/content/$1index.html -f
RewriteRule ^(.*)$ /content/$1 [L]
# 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
DokuWiki .htaccess
RewriteEngine on
RewriteBase /path/to/wiki
RewriteRule ^_media/(.*) lib/exe/fetch.php?media=$1 [QSA,L]
RewriteRule ^_detail/(.*) lib/exe/detail.php?media=$1 [QSA,L]
RewriteRule ^_export/([^/]+)/(.*) doku.php?do=export_$1&id=$2 [QSA,L]
RewriteRule ^$ doku.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) doku.php?id=$1 [QSA,L]
I would think that all you need to do is omit the path to wiki and content directories from your .htaccess file in the root and include the path in the first rewriterule.
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{DOCUMENT_ROOT}/content/$1 -f [OR]
RewriteCond %{DOCUMENT_ROOT}/content/$1index.php -f [OR]
RewriteCond %{DOCUMENT_ROOT}/content/$1index.html -f
RewriteRule ^(path/to/wiki/.+/?)$ /content/$1 [L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_URI} !^/(path/to/wiki|content)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

How to remove extensions from urls in the website

I try to remove extensions from the url by creating a .htaccess page in the root folderwith the following code
RewriteEngine
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php
but it is not working pls help me out......
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule .* $0.php
use this code in your .htaccess file
and remove the extensions of your php files in a href itself

Zend Framework with Wordpress in subdirectory

I want to serve wordpress from public_html/blog. I have already install zend framework and i would like to know how to achieve this. My .htaccess file looks like
RewriteEngine On
RewriteRule ^\.htaccess$ - [F]
RewriteCond %{HTTP_HOST} ^domain\.example\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.domain\.example\.com$
RewriteRule ^/?$ "http\:\/\/simple\.com\/" [R=302,L]
RewriteCond %{HTTP_HOST} ^other\-domain\.example\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.other\-domain\.example\.com$
RewriteRule ^/?$ "http\:\/\/simple\.com\/" [R=302,L]
RewriteCond %{REQUEST_URI} =""
RewriteRule ^.*$ public/index.php [NC,L]
RewriteCond %{REQUEST_URI} !^/public/.*$
RewriteRule ^(.*)$ /public/$1
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^.*$ - [NC,L]
RewriteRule ^public/.*$ public/index.php [NC,L]
I am totaly green in htaccess files and this is my first case with it. Is that structure already correct?
In your ZF htaccess, allow apache to service existing files and directories:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
Now apache will see that /blog is a real folder and then load the htaccess inside there (your WP htaccess) when the user goes to /blog.
You should be able to have your two htaccess rules separate without the need for complex routing

Resources