Reputation: 22158
I was trying to rewrite or redirect a URL with a regular expression based on the negation of a word.
The scenario is as following:
I have a wordpress installed on example.com/wp-blog
but the visualization is through API on example.com/blog
. I need to disable the access to /wp-blog
and redirect it to /blog
but preserving the access to /wp-blog/wp-admin
.
I try the following condition on htaccess:
RewriteCond ^wp-blog/((?!wp-admin).)*$ [NC]
RewriteRule ^(.*)$ /blog/$1 [R=301,L]
But with no success.
I also try this:
Redirect 301 ^wp-blog/((?!wp-admin).)*$ /blog/$1
And also this:
RewriteRule ^wp-blog/wp-admin $ /wp-blog/wp-admin $1 [L,NC]
RewriteRule ^wp-blog/wp-login.php $ /wp-blog/wp-login.php $1 [L,NC]
RewriteRule ^wp-blog/(?!.*wp-admin)$ /blog/$1 [R=301,L,NC]
I have no success with all combinations I try. So how can I redirect/rewrite /wp-blog
to /blog
but with access to /wp-blog/wp-admin
?
Thank you so much.
Upvotes: 0
Views: 219
Reputation: 48711
You could use request_uri to test if following path is wp-admin then write a rule to rewrite every thing to /blog
:
RewriteCond %{REQUEST_URI} ^/?wp-blog(?!/wp-admin)
RewriteRule ^/?wp-blog(/.*)? blog$1 [R=301,L]
Upvotes: 1
Reputation: 1052
No need to do anything with .htaccess, all you can be done with WordPress directly.
its can be done in two step
Step 1 : on your root create index.php with below content
<?php
/**
* Front to the WordPress application. This file doesn't do anything, but loads
* wp-blog-header.php which does and tells WordPress to load the theme.
*
* @package WordPress
*/
/**
* Tells WordPress to load the WordPress theme and output it.
*
* @var bool
*/
define('WP_USE_THEMES', true);
/** Loads the WordPress Environment and Template */
require( dirname( __FILE__ ) . '/wp-blog/wp-blog-header.php' ); /** here wp-blog is place as your folder name */
Step 2 : now change "staging.domain.com" to "staging.domain.com/wp-blog" in your database ( for this download sql > open & edit for replace > upload new sql ).
Now you full site run on staging.domain.com URL but files are call from "wp-blog" folder.
Upvotes: 0