Htaccess inside a folder - wordpress

We are trying to make a change of domain for a wordpress.
The blog is in a subfolder called "blog".
The old domain is
http://www.peluches-et-jouets-en-bois.fr/blog
We want all the pages of the blog to be redirected to :
http://www.peluchesetjouetsenbois.fr/blog
It does work for the home page of the blog, but as soon as we go to another page of the blog, then it doesn't work anymore.
Here is what we have so far.
WordPress
<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]
RewriteCond %{HTTP_HOST} ^(www\.)?peluches-et-jouets-en-bois.fr$
RewriteRule ^(.*)$ http://www.peluchesetjouetsenbois.fr/blog/$1 [L,R=301]
</IfModule>
# END Wo
If someone can help us on that, that would be great :)
Thanks a lot

Place redirection rule before existing WP rules:
RewriteEngine On
RewriteBase /blog/
RewriteCond %{HTTP_HOST} ^(www\.)?peluches-et-jouets-en-bois\.fr$ [NC]
RewriteRule ^(.*)$ http://www.peluchesetjouetsenbois.fr/blog/$1 [L,NE,R=301]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]

Related

Redirect a subdomain to a new URL

I have a client that had a main site in Joomla and a blog in WordPress. We just made everything one WordPress site.
What I need help with is redirecting the subdomain (e.g. blog.example.org) to the new URL (example.org/blog).
I believe this needs to get done with .htaccess and it needs to be integrated with the WordPress stuff, too.
Here's where I got so far:
# 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]
RewriteCond %{HTTP_HOST} ^example.health-access.org
RewriteRule ^(.*)$ http://example.org/blog/$1 [L,NC,QSA]
</IfModule>
# END WordPress
But it's not working. Any thoughts and help are greatly appreciated.
You just need to change the order:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^example.health-access.org [NC]
RewriteRule ^(.*)$ http://example.org/blog/$1 [R=301,L,QSA]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
#END WordPress
Try this:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^yoursubdomain\.yourdomain\.com$ [
RewriteRule ^(.*) http://www.newdomain.com/?param=data&uparam2=data

How to Redirect example.com/blog/month/post to example.com/post

I recently created a new droplet to use with Serverpilot. So, I created a new droplet and migrated contents from my old droplet using All in one WP migration plugin. In the permalink settings I have maintained the previous permalink structure which was example.com/post-name and saved the settings.
But, all of a sudden, I can see Organic traffic (search engine traffic) to example.com/blog/dd-mm-yy/post-name which is obviously returning not found 404 page.
I don't know if it is a temporary issue, as I have correct permalink structure setup already.
Now I want to redirect any traffic coming to example.com/blog/date/post-name to example.com/post name. For all the posts. Basically, I want to strip off /blog/dd-mm-yy from all the posts so that the user can be redirected to example.com/post-name.
Any way to do it from .htaccess?
.htaccess file looks like this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ %{HTTP_HOST}/$1 [R=301,L] RewriteRule ^blog/(?:\d+/)+/([^/]+/?)$ /blog/$1 [L,NC,R=301]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Inside /.htaccess have this rule as very first rule:
RewriteEngine On
RewriteBase /
RewriteRule ^blog/(?:\d+/)+/([^/]+/?)$ /blog/$1 [L,NC,R=301]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ %{HTTP_HOST}/$1 [R=301,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

htaccess rewrite : Wordpress directory + subdomain redirect not working together

I moved a Wordpress blog from blog.mywebsite.com to mywebsite.com/blog/ .
Everything was OK until I tried to redirect old links to the new location.
I want people asking http://blog.mywebsite.com/2014/09/article-example/ to find themselves in http://mywebsite.com/blog/2014/09/article-example/
But the htaccess is already completed with some rules using the keyword "blog"
RewriteEngine On
RewriteBase /blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
I cannot find the way to write the rule
Today I have an error 500 with this link : http://blog.mywebsite.com/2014/09/article-example/
I would like at least to redirect to mywebsite.com/blog/ , ideally to http://mywebsite.com/blog/2014/09/article-example/
Any idea?
Thanks and good day everyone :)
You can replace your current htaccess code by this one
RewriteEngine On
RewriteBase /blog/
RewriteCond %{HTTP_HOST} ^blog\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/blog/$1 [R=301,L,QSA]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [L]

Want to run wordpress in a subdirectory and keep my main site separate in the root

I have an eCommerce website in the root directory and want to move my blog to a subdirectory. I successfully made the move from another domain to this one but when I attempt to go to the blog home page it re-directs to my eCommerce site's home page.
The eCommerce site - http://www.heavytshirt.com
The blog location - http://www.heavytshirt.com/blog
The .htaccess file in the blog directory looks like this:
RewriteEngine on
RewriteBase /
# BEGIN WordPress
<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>
# END WordPress
And the .htaccess file in the root directory looks like this:
DirectoryIndex /mm5/merchant.mvc?Screen=SFNT
RewriteEngine On
RewriteRule ^mm5/admin.mvc? - [L]
RewriteCond %{REQUEST_FILENAME} !-s
RewriteRule ^product/([^/.]+).html$ /mm5/merchant.mvc?Screen=PROD&Product_code=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-s
RewriteRule ^category/([^/.]+).html$ /mm5/merchant.mvc?Screen=CTGY&Category_code=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-s
RewriteRule ^product/([^/]+)/([^/.]+).html$ /mm5/merchant.mvc?Screen=PROD&Category_code=$1&Product_code=$2 [L]
RewriteCond %{REQUEST_FILENAME} !-s
RewriteRule ^([^/.]+).html$ /mm5/merchant.mvc?Screen=$1 [L]
### End - Inserted by Miva Merchant
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{http_host} ^heavytshirt.com [nc]
RewriteRule ^(.*)$ http://www.heavytshirt.com/$1 [r=301,nc]
# BEGIN WordPress
<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>
# END WordPress
Currently I am able to type in a subsequent sub directory and get to a post - Like:
http://www.heavytshirt.com/blog/category/summershirts/
What can I do to make the blog home page come up when someone types in http://www.heavytshirt.com/blog
And not affect the main site at www.heavytshirt.com
I'm not looking into your apache configuration, since I believe it can easily be configured within WordPress.
Go into your WordPress administration panel, and move to Settings / General Settings.
Now change the values of WordPress Address (URL) and Site Address (URL) accordingly. Read this WordPress Codex article for more details.
Your issue is because you have set
DirectoryIndex /mm5/merchant.mvc?Screen=SFNT
Because /blog/ is a directory and the rules you have set are matching that as the directory index for /blog/ (because the directory actually exists).
You will have to combine the two Rewrite Directives to get the desired result (you don't need RewriteEngine On in there twice).
Probably better that you start from scratch testing line by line to make sure you get the desired result.
I can't test this, but you get the idea:
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteRule ^mm5/admin.mvc? - [L]
RewriteCond %{REQUEST_FILENAME} !-s
RewriteRule ^product/([^/.]+).html$ /mm5/merchant.mvc?Screen=PROD&Product_code=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-s
RewriteRule ^category/([^/.]+).html$ /mm5/merchant.mvc?Screen=CTGY&Category_code=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-s
RewriteRule ^product/([^/]+)/([^/.]+).html$ /mm5/merchant.mvc?Screen=PROD&Category_code=$1&Product_code=$2 [L]
RewriteCond %{REQUEST_FILENAME} !-s
RewriteRule ^([^/.]+).html$ /mm5/merchant.mvc?Screen=$1 [L]
RewriteCond %{http_host} ^heavytshirt.com [nc]
RewriteRule ^(.*)$ http://www.heavytshirt.com/$1 [r=301,nc]
RewriteBase /blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]

Redirect to a new domain & change url structure htaccess

I am trying to redirect a wordpress blog from an old domain to a new domain and changing the structure of the urls on the new domain.
So I want www.domainA.com to redirect to test.domainB.com/folder/
and www.domainA.com/2001/12/some-post to redirect to test.domainB.com/folder/some-post
This is what I currently have in my htaccess file. I have managed to achieve my second objective, but if you go to www.domainA.com, it does not redirect to test.domainB.com/folder/ All the other pages redirect properly aside from the homepage.
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?domainA\.com$ [NC]
RewriteRule ^([0-9]+)/([0-9]+)/(.*)$ http://test.domainB.com/folder/$3 [R=301,NC,L]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
I am sure I am missing something elemetary, but I can't seem to figure it out :(
Try this code :
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?domainA\.com$ [NC]
RewriteRule ^/?\d+/\d+/(.*)$ http://test.domainB.com/folder/$1 [NC,L,R=301]
RewriteCond %{HTTP_HOST} ^(www\.)?domainA\.com$ [NC]
RewriteRule ^/?$ http://test.domainB.com/folder/ [NC,L,R=301]
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ /index.php [L]

Resources