WordPress URL/folder rewrite in htaccess - wordpress

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

Related

WordPress Permalinks only work with index.php in the URL

When I try to change my WordPress Permalink settings, links to posts and pages return a 404 page. I have found the only way to get them to work is to either use Plain permalinks or to include /index.php/ in my permalink url, like domain.com/index.php/postname. How can I get them to work without index.php being part of the URL?
My .htaccess is below, and I have also used the .htaccess suggested at https://wordpress.org/support/article/using-permalinks/#creating-and-editing-htaccess, but changes to the permalinks puts the code below back into the htaccess file. Mod_rewrite is enabled on my Apache server.
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /wordpress/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wordpress/index.php [L]
</IfModule>
# END WordPress

wordpress wp-content/uploads folder 301 redirect to S3 bucket by cloudfrond CDN by .htaccess issues

See below, the .htacess file from Wordpress. If I remove the part starting from # BEGIN WordPress, all the image file URLs will be changed to d28rt1vkpsdxas.cloudfront.net/someimage.png successfully.
However, all the internal links will be unable to access (only the home page can access). The error is
Not Found The requested URL /shop/ was not found on this server.
But if I keep the part start from # BEGIN WordPress, the CDN redirect will not work anymore. All photos are missing.
Options +FollowSymlinks
RewriteEngine on
Rewriterule ^wp-content/uploads/(.*)$ http://exampled28t1vkps.cloudfront.net/$1 [r=301,nc]
# 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
You’re missing the [L] flag, which prevents other rules from redirecting:
Rewriterule ^wp-content/uploads/(.*)$ http://exampled28t1vkps.cloudfront.net/$1 [r=301,nc,l]

Wordpress: Create static permalink in htaccess

I want to put a static permalink in the .htaccess file. For example when I go to the http://www.example-page.com/testsite the server redirect to this http://www.example-page.com/wp-admin/example.php?test=data
My problem is that I didn't want to destroy the permalink structure of the WordPress blog.
My .htaccess file code looks like as follows:
# 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
Thanks for your help.
Add this rule after RewriteBase /
RewriteRule ^testsite$ /wp-admin/example.php?test=data [R=301,L]
It will intercept only the specified URI and redirect it.
Other WP's permalinks should work as usual.

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>

htaccess issue with website having WordPress directory containing Cakephp website

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.

Resources