I have a site that redirects from blog.domain.com to domain.com/blog
Its a WP site that also has a permalink redirect to change the url from date name to post.
The htaccess works perfectly on the blog.domain.com and it also works perfectly on the domain.com/blog.
The only issue is that coming from blog.domain.com/* ends with a double 301.
I have included both htaccess so you can see.
What I am looking to do is to get the blog.domain.com/ to pre apply the redirect match before redirecting to the domain.com/blog site.
Thanks
BLOG.DOMAIN.COM
RewriteEngine on
RewriteCond %{HTTP_HOST} ^blog\.EXAMPLE\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.blog\.EXAMPLE\.com$
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^(.*)$ "https\:\/\/EXAMPLE\.com\/blog\/$1" [R=301,L]
DOMAIN.COM/BLOG
RedirectMatch 301 ^/blog/([0-9]{4})/([0-9]{2})/([0-9]{2})/(?!page/)(.+)$ https://EXAMPLE.com/blog/$4
# 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>
Related
I am working on a hacked site that has thousands of 404 errors now that I have fixed it. I want to redirect everything in the folders that were from the hack back to the home page. For example, this is one of the hacked urls:
http://www.truckeeriverrock.com/scategory/aqrqxjfo-x10001-zlggclj/whlhgxtx-y298119-bucavsa/
I am trying to do this via the .htaccess file. It is a wordpress website so I already have some standard rewrite rules. Basically I tried the following but it breaks the site with an internal server error:
# 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 ^scategory/(.*) http://www.truckeeriverrock.com/$1 [R=301,L]
RewriteRule ^whosonline/(.*) http://www.truckeeriverrock.com/$1 [R=301,L]
RewriteRule ^admintools/(.*) http://www.truckeeriverrock.com/$1 [R=301,L]]
</IfModule>
# END WordPress
If I take out the following rewrite rules it works but of course it doesn't redirect:
RewriteRule ^scategory/(.*) http://www.truckeeriverrock.com/$1 [R=301,L]
RewriteRule ^whosonline/(.*) http://www.truckeeriverrock.com/$1 [R=301,L]
RewriteRule ^admintools/(.*) http://www.truckeeriverrock.com/$1 [R=301,L]]
Could someone help me with my rules?
Keep your 301 rules before default WP rules.
RewriteEngine On
RewriteBase /
RewriteRule ^scategory/(.*) http://www.truckeeriverrock.com/$1 [R=301,L]
RewriteRule ^whosonline/(.*) http://www.truckeeriverrock.com/$1 [R=301,L]
RewriteRule ^admintools/(.*) http://www.truckeeriverrock.com/$1 [R=301,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
This is because WP rule changes REQUEST_URI to /index.php hence your rules fail to match given patterns.
I'm trying to do a .ca to .com domain 301 redirect however no matter what I do it doesn't work. I've not actually done this before so I've serached about it but the code I have in doesn't work? As my .ca domain just goes to a "not found" page. Shouldn't be be redirecting to my .com domain
Here is the code I have in my .htaccess
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.ca [NC,OR]
RewriteCond %{HTTP_HOST} ^example.ca [NC]
RewriteRule ^(.*)$ http://example.com/$1 [L,R=301,NC]
I have a bunch of rules form W3TC and this snippet which I'm assuming has to do with a landing page plugin we have on the site:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{QUERY_STRING} !lp-variation-id
RewriteRule ^go/([^/]*)/([0-9]+)/ /go/$1?lp-variation-id=$2 [QSA,L]
RewriteCond %{QUERY_STRING} !lp-variation-id
RewriteRule ^go/([^/]*)? /wp-content/plugins/landing-pages/modules/module.redirect-ab-testing.php?permalink_name=$1 [QSA,L]
RewriteRule ^landing-page=([^/]*)? /wp-content/plugins/landing-pages/modules/module.redirect-ab-testing.php?permalink_name=$1 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Advice is great! Thanks!
I am new to HTACCESS and have a very specific question regarding 301 redirects. I am looking to redirect all .co.uk urls to .co but also I want to redirect all suburls to the root URL so for example I want
http://virtualfiles.co.uk/scenarios.html -> http://virtualfiles.co
A lot of these pages don't exist anymore so I would rather just relocate the user to the top level domain rather than a page that doesn't exist on the old or new domain.
I am set up on WordPress and the code I have so far is below. Any help would be amazing.
# 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
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) index.php [NC]
You can try this in your domain1/.htaccess :
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)?virtualfiles\.co\.uk$ [NC]
RewriteRule ^(.*)$ http://virtualfiles.co/$1 [R=302,L]
Or Try With RedirectMatch
RedirectMatch 301 ^/(.*)$ http://virtualfiles.co/$1
I'm currently moving a site (shop) to a new domain and putting in its place a non-shop version (made in wordpress) of the site. The aim is for most of the urls to redirect to the new domain except the few pages that the new site has. I've found other posts on stackoverflow but unfortunately I can't seem to get it working. Any help would be much appreciated, Thanks Jason.
The urls I need to exclude are:
/ (Homepage)
/news and its posts /news/post-name
/products and its posts /products/post-name
/offers and its posts /offers/post-name
/our-philosophy
/our-team
/our-dream
Here's what I tried:
<IfModule mod_rewrite.c>
RewriteEngine on
#Home
RewriteCond %{REQUEST_URI} !^/
#News
RewriteCond %{REQUEST_URI} !^/news(.*)
#Products
RewriteCond %{REQUEST_URI} !^/products(.*)
#Offers
RewriteCond %{REQUEST_URI} !^/offers(.*)
#Philosophy
RewriteCond %{REQUEST_URI} !^/our-philosophy(.*)
#Team
RewriteCond %{REQUEST_URI} !^/our-team(.*)
#Dream
RewriteCond %{REQUEST_URI} !^/our-dream(.*)
RewriteRule (.*) http://www.cotswold-fayre.co.uk/$1 [R=301,L]
</IfModule>
# 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
try adding the following to your .htaccess file
RewriteEngine on
#Home: Exclude the home Page
RewriteCond %{REQUEST_URI} !^/$ [OR]
#News: exclude anything that starts with /news, /products etc
RewriteCond %{REQUEST_URI} !^/(news|products|offers|our-philosophy|our-team|our-dream) [NC]
RewriteRule (.*) http://www.cotswold-fayre.co.uk/$1 [R=301,L]
Trying to set up a 301 redirect for a change in domain. I'm using Textpattern which already has a mod rewrite. When adding the redirect I'm prompted with a error page on the site, stating that the page has resulted in too many redirects!
This is the htaccess file in use...
<IfModule mod_rewrite.c>
RewriteEngine On
#RewriteBase /relative/web/path/
RewriteRule (.*) http://www.domain.com/$1 [R=301,L] #(this has been added to the default textpattern htaccess file)
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.+) - [PT,L]
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^(.*) index.php
RewriteCond %{HTTP:Authorization} !^$
RewriteRule .* - [E=REMOTE_USER:%{HTTP:Authorization}]
</IfModule>
Many thanks for any advise you can give.
From what domain you try to redirect? May be you have set cycling - trying to redirect from site.com to site.com?
Add this after RewriteEngine On
RewriteCond %{HTTP_HOST} ^(?!www.yournewdomain.com$).*$
RewriteRule (.*) http://www.yournewdomain.com/$1 [R=301,L]