301 redirect with htaccess & textpattern - .htaccess

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]

Related

TYPO3 9.5.20 .htaccess redirect - too many redirects

I am trying to redirect all pages to /uk apart from the home page and the /uk page but I get localhost redirected you too many times when it loads the /uk page. I thought !^/uk$ would solve this. Any help is greatly appreciated
Here is my code in the .htaccess file;
# Add your own rules here.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^/$ [NC]
RewriteCond %{REQUEST_URI} !^/uk$ [NC]
RewriteCond %{HTTP_COOKIE} !cookieConfirmed=1;? [NC]
RewriteRule . /uk [L,R=301]
</IfModule>
These should work:
RewriteCond %{REQUEST_URI} !^/$ [NC]
RewriteCond %{REQUEST_URI} !^/uk/?$ [NC]
RewriteRule ^(.*) /uk [L,R=301]
Maybe you added a slash to all URLs so the too many redirects occurs? So I made a / at the end optional.

htaccess complex redirect advice

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>

301 redirect for .ca domain to .com domain

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!

URL redirect issue

I have a problem with redirecting single webpages within my website.
I am trying to redirect https://job-center.hu/munkaero_kozvetites/ to https://job-center.hu/munkaero-kozvetites/ and I am using the following htaccess file to do this:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?q=/$1 [QSA]
</IfModule>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.allasajanlat.job-center.hu [NC]
RewriteRule ^(.*)$ https://allasajanlat.job-center.hu/$1 [L,R=301]
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.job-center.hu [NC]
RewriteRule ^(.*)$ https://job-center.hu/$1 [L,R=301]
Options -Indexes
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
Redirect 301 /munkaero_kozvetites/ https://job-center.hu/munkaero-kozvetites/
#SetEnv skip-cache
The result is a strange URL and I am not sure if this is OK.
Would this be considered as duplicate content by Google or this is OK as it is.
Thanks for your help in advance.
For your question about google, Redirect 301 is a permanently redirect, which means google will consider both sites the same content.

.htaccess 301 redirect subdomain and all files and folders to root

I have been beating my head up against a wall for a day trying to figure this out. If you know how to do this and can help, it would be greatly appreciated.
I am trying to 301 redirect everything from www.example.com to the root domain at example.com
The following works to redirect www.example.com as intended, but requests for other files or folders are returning a 302. This is a Wordpress Multisite install, but it only has one domain mapped at this time.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# BEGIN WordPress
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
# add a trailing slash to /wp-admin
RewriteRule ^wp-admin$ wp-admin/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^(wp-(content|admin|includes).*) $1 [L]
RewriteRule ^(.*\.php)$ $1 [L]
RewriteRule . index.php [L]
# END WordPress
# Link re-directs from old website.
RewriteCond %{HTTP_HOST} ^www.example.com/(.*)$ [NC]
RewriteRule ^/?(.*)$ http://example.com$1 [R=301,L]
# Other
php_value memory_limit 500M
Can anyone help?? Please and thank you.
YOu need to add your redirect rule before all of your routing rules (e.g. wordpress stuff). You are also missing a slash in your target and the HTTP_HOST does not contain any path info, just the hostname. So this:
# Link re-directs from old website.
RewriteCond %{HTTP_HOST} ^www.example.com$ [NC]
RewriteRule ^/?(.*)$ http://example.com/$1 [R=301,L]
needs to go right under the RewriteEngine On at the very top of the htaccess file.

Resources