htaccess issue with website having WordPress directory containing Cakephp website - wordpress

I am working on website having front website made with WordPress and a WordPress directory
contains a dashboard folder having a cakephp website. Everything is working perfectly on my
local system but when I migrated the whole website to online server I am unable to access
www.mywebsite.com/dashboard folder as I read here
https://wordpress.stackexchange.com/questions/20152/cannot-access-non-wordpress-subdirectories-as-wordpress-overrides-them-with-a-40
this is a htaccess issue but I dont know htaccess coading at all so this link was confusing
to me if any one could explain me (in simple way) why this problem occurs? and how to
solve this problem? will be helpfull to me
my wordpress 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 cakephp htaccess which is in wordpress-install-directory/dashboard/cakephp-install
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>

It should be just a case of changing your .htaccess to match the below
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase wordpress-install-directory/dashboard
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
Doing the above will tell cake that the needed files are within instal-directory/dashboard.
You will also need to make the same change to webroot and app .htaccess

If they are in different folders with independent .htaccess files, you might try to set the base directory for cakephp, like this:
<IfModule mod_rewrite.c>
RewriteEngine on
# Could be dashboard or cakephp-install
RewriteBase /dashboard
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>

From a stackoverflow answer here:http://stackoverflow.com/questions/2322559/htaccess-wordpress-exclude-folder-from-rewriterule/2350305#2350305
add
RewriteCond %{REQUEST_URI} !^/(dashboard|dasboard/.*)$
before the last RewriteRule on your .htaccess file on wordpress directory and it should work.

Related

WordPress URL/folder rewrite in htaccess

I am trying to mask certain folder in a WordPress installation using the Htaccess file. I am aware that there are plugins available to do exactly what I want but, I do not want to add even more plugins that may have overlapping functions.
The result I am trying to achieve is :
from
example.com/wp-include/js/jquery
example.com/assets/themes/........
example.com/assets/themes/parent_theme/......
example.com/wp-admin/admin-ajax.php
to
example.com/lib/js/jquery.......
example.com/assets/layouts/.......
example.com/assets/layouts/main/........
example.com/ajax
I have tried inputting the code as below but, this just breaks WP with A 500 internal error
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteRule ^lib/(.*) /wp-includes/ [QSA,L]
RewriteRule ^assets/layouts/(.*) /assets/themes/ [QSA,L]
RewriteRule ^assets/layouts/main/(.*) /assets/themes/parent_theme/ [QSA,L]
RewriteRule ^ajax /wp-admin/admin-ajax.php [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
I have also tried placing the code as follows but this does not provide any results at all (it does not change the 'wp-include' to 'lib')
# BEGIN Custom URL Folder Rewrites
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^lib/(.*) /wp-includes/ [QSA,L]
RewriteRule ^assets/layouts/(.*) /assets/themes/ [QSA,L]
RewriteRule ^assets/layouts/main/(.*) /assets/themes/parent_theme/ [QSA,L]
RewriteRule ^ajax /wp-admin/admin-ajax.php [QSA,L]
</IfModule>
# END Custom URL Folder Rewrites
I would be grateful for any help in solving this problem without the use of an additional function heavy plugin.
This WP installation does not use the standard wp-content folder but a custom folder 'assets'
I would also like to be able to use the code outside of the BEGIN WordPress and END WordPress tags so that I have full control and WP does not remove or edit them.
Use this rule and it will work
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^wp-includes/(.*) lib1/$1
</IfModule>
# END WordPress

htaccess rewrite issue excluding folder

I have a Wordpress site that has a rewrite rule. I also have a non-wordpress folder, but I can't access it because of this rule. So I read that i should enter RewriteEngine Off in the htaccess of the non-wordpress folder, unfortunately I still get an Error 404 on that page (it works fine if I remove the Wordpress rewrite).
Here is the htaccess in the root:
# 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
What am I doing wrong?
Many thanks!
Matt
Add this right under RewriteBase /:
RewriteRule ^folder/ - [L]
where folder is the folder you want to exclude.

redirect url in wordpress wp-admin dashboard via htaccess

I've been trying to redirect a url in my wordpress wp-admin dashboard from /wp-admin/admin.php?page=for_buyers to wp-admin/for-buyers/.
Is there any way to correctly do this? I've tried modifiying my .htaccess file as can be seen below, but it's not working.
# 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]
RewriteRule ^wp-admin/for-buyers/$ /wp-admin/admin.php?page=for_buyers
</IfModule>
# END WordPress
UPDATE: I have been able to do it, but it now causes a redirect loop.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^/wp-admin/admin.php?page=for_buyers wp-admin/for-buyers/$
</IfModule>
You do not need to redirect your url but just rewrite it.
Take a look here
Hope this helps you!

Wordpress inside Cakephp

I have installed Wordpress inside Cakephp's /app/webroot/blog/ folder and changed the wordpress permalink settings to Month and name (eg. http://abc.com/blog/2013/02/sample-post/).
Now when i am viewing a post i am getting Missing Controller(Error: BlogController could not be found).
I want to change the cakephp routes so that anything with /blog/* will point to webroot blog folder.
Can anybody help me on this?
When we change the permalink settings of Wordpress, it generates a .htaccess file, if there is required permission else we have to create it.
In the above case there was no .htaccess file inside /blog/ folder. I created it with the following mod_rewrite rules as provided by Wordpress while changing permalink settings.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>
After this every thing works fine.
There is no need to put the blog folder in webroot folder. You can access your folder by making slight changes in your .htaccess file. Just put your wordpress folder on root of cakephp with app folder and change .htaccess as given below.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule (blog/.*) $1 [L] # adjust the regex to what you want.
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
I tried both the above codes but none work for me.. then i found something by my own and it worked..So here it is ,, hope this will help some.
First Add the WordPress folder inside the webroot folder as blog. Inside blog paste the WordPress directories and files.. install the WordPress.. Now you will see in the WordPress admin general settings WordPress Address as http://cakephp/blog/app/webroot/blog, Change it to http://cakephp/blog. Save it ..
Now look for the .htaccess file in WordPress install root folder change RewriteBase and RewriteRule (last one ) to RewriteBase /blog/ and RewriteRule . /blog/index.php [L]
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteRule ^index\.php$ – [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>

Wordpress redirect to non-existing language-directory

following situation. I have a blog which is installed in /blog/ - the site is available in 3 languages (de, at, ch), each one should link to /language/blog/, but they should all show the content of /blog/ (why you ask? SEO purposes...)
This is the .htaccess I've got:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/(de|at|ch)/blog/(.*)$
RewriteRule ^(.*)$ /blog/%2?hl=%1 [L]
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
#RewriteBase /blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>
The language-directories do not really exist, only the impression should be made.
The "hl" (hreflang) query param is for later use in the script - the param is being sent as expected. So now it is basically working (tested on a non-wordpress directory) - but when I'm using it in the Wordpress environment, all I get is the content of the 404.php-Template.
Used version: 3.4.2
Any ideas? Thanks in advance.
You should put the code you added in a separate htaccess that is in the root, and not in the /blog directory.

Resources