Trying to proper make a redirect loop for site
tryng to redirect all sites like
34www.arsenal.org.pl / 46www.arsenal.org.pl / ww32w.arsenal.org.pl / dalx.arsenal.org.pl
to arsenal.org.pl
http://www.webconfs.com/htaccess-redirect-generator.php gave me the code
Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) http://arsenal.org.pl/$1 [R=301,L]
but it give redirect loop in Wordpress
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} !^(www\.)arsenal.org.pl$
RewriteCond %{HTTP_HOST} ^(.*?)\.arsenal.org.pl$
RewriteRule ^(.*)$ http://arsenal.org.pl/$1 [r=301,nc]
ty Cbroe for hint :)
Related
I'm trying to move a site from a set of static html pages on one domain, to a new domain on WordPress. So I want each old page redirect to the corresponding new page on the new domain.
The structure on old domain is like so:
http://www.example.com/page.html
and the new domain has this structure:
http://www.example-new.com/category/sub-category/page/
So I tried this:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^http://www.domain-old\.com/page1.html [NC]
RewriteRule ^(.*)$ http://www.domain-new.com/new-category/new-sub-category/page1/ [R=301,L]
RewriteCond %{HTTP_HOST} !^http://www.domain-old\.com/page2.html [NC]
RewriteRule ^(.*)$ http://www.domain-new.com/new-category/new-sub-category/page2/ [R=301,L]
RewriteCond %{HTTP_HOST} !^http://www.domain-old\.com/page3.html [NC]
RewriteRule ^(.*)$ http://www.domain-new.com/new-category/new-sub-category/page3/ [R=301,L]
RewriteCond %{HTTP_HOST} !^http://www.domain-old\.com/page4.html [NC]
RewriteRule ^(.*)$ http://www.domain-new.com/new-category/new-sub-category/page4/ [R=301,L]
RewriteCond %{HTTP_HOST} !^http://www.domain-old\.com/page5.html [NC]
RewriteRule ^(.*)$ http://www.domain-new.com/new-category/new-sub-category/page5/ [R=301,L]
And it works (kinda). The only GIANT problem is that now all pages redirect to the first new page, in this case http://www.domain-new.com/new-category/new-sub-category/page1/
Obviously I'm not an expert, but I spent hours on Google looking for an answer and trying things and can't figure how to do this, the closest I have found is about redirecting domain A to domain b removing the extension, so this is my last resource.
Any help appreciated!
This condition is the main problem:
RewriteCond %{HTTP_HOST} !^http://www.domain-old\.com/page1.html [NC]
This will always evaluate to true because variable HTTP_HOST only matches host name part of a web request not the complete URL.
You can use this single rule in your .htaccess:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(?:www\.)?domain-old\.com$ [NC]
RewriteRule ^([\w-]+)\.html$ http://www.domain-new.com/new-category/new-sub-category/$1/ [R=301,L,NC]
You are over-complicating this. Instead of all that processing, just use the Redirect Directive.
Redirect 301 /page1.html /new-category/new-sub-category/page1/
Redirect 301 /page2.html /new-category/new-sub-category/page2/
Redirect 301 /page3.html /new-category/new-sub-category/page3/
Redirect 301 /page4.html /new-category/new-sub-category/page4/
I'm working on a wordpress site. And just installed SSL. It has been installed correctly but I want to redirect visitors to the https url for certain pages only. I also want to force browser to use http for other pages.
I know this can be done with .htaccess and tried several things as well. But unable to get this as I need. I'm a novice at handling .haccess rewrite rules and can't find the docs that can guide me.
For example, I need to force browser to use https for this two urls:
http://www.example.com/sells/payment/
http://www.example.com/customer/login/
and for all other urls to just use normal http forcefully. What kind of rules I need to write?
Update 1
I also have a rule that redirects non-www url to a www url, and that might be conflicting with these rules. Here is how I redirect all non-www urls to www urls.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
The issue I'm facing is, after applying https rules, it is redirected to https://www.www.example.com/sells/payment/ which is a wrong url.
Any idea for fixing this?
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^(sells/payment|customer/login)/ - [E=MY_URL:1]
RewriteCond %{HTTPS} off
RewriteCond %{ENV:MY_URL} 1
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=302,L]
RewriteCond %{HTTPS} on
RewriteCond %{ENV:MY_URL} !=1
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=302,L]
UPDATE:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^(sells/payment|customer/login)/ - [E=MY_URL:1]
RewriteCond %{HTTPS} off
RewriteCond %{ENV:MY_URL} 1
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=302,L]
RewriteCond %{HTTPS} on
RewriteCond %{ENV:MY_URL} !=1
RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [R=302,L]
This what I've used consistently across my projects where I have similar use-cases as yourself:
RewriteCond %{SERVER_PORT}s ^(443(s)|[0-9]+s)$
RewriteRule ^(.+)$ - [env=askapache:%2]
# redirect urls with index.html to folder
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.html\ HTTP/
RewriteRule ^(([^/]+/)*)index\.html$ http%{ENV:askapache}://%{HTTP_HOST}/$1 [R=301,L]
# change // to /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(.*)//(.*)\ HTTP/ [NC]
RewriteRule ^.*$ http%{ENV:askapache}://%{HTTP_HOST}/%1/%2 [R=301,L]
This is an excerpt from a site where I found the solution, so I can't take credit for it:
Smart HTTP and HTTPS .htaccess Rewrite
I haven't tried it, but can you handle it the same way you do cononcial URLs?
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.com/your-page
RewriteRule (.*) https://www.example.com/your-page [R=301,L]
I'd like rewrite a URL string from ?s= to /search/ with .htaccess.
Example: http://hello.com/?s=hey => http://hello.com/search/hey
How can I do this?
May be something like this
RewriteEngine On
RewriteRule ^search/(.*) index.php?s=$1 [QSA,L]
This way you will be accessing your site like
http://hello.com/search/hey will be interpreted as http://hello.com/index.php?s=hey
hope this helps
Put this code in your .htaccess under DOCUMENT_ROOT:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
# external redirect from index.php?s=key to search/key
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+index\.php\?s=([^\s]+) [NC]
RewriteRule ^ search/%1? [L,R,NC]
# external redirect from search/key to index.php?s=key
RewriteRule ^search/(.+)$ index.php?s=$1 [L,NC,QSA]
Thanks for the answers guys, this works for me, taken from here.
RewriteCond %{QUERY_STRING} s=(.*)
RewriteRule ^$ /search/%1? [R,L]
I have an SSL certificate installed on my website and I would like to redirect two specific pages to https, e.g. http://domain.com/?page=credit and http://domain.com/?page=submit_form to https.
My web host added the following code to my .htaccess file, above the Wordpress settings but it still doesn't redirect the pages:
Redirect /?page=credit https://domain.com/?page=credit
RewriteEngine On
RewriteCond %{SERVER_PORT} !^443$
RewriteCond %{QUERY_STRING} (^|&)p=(credit)($|&)
RewriteRule (.*) https://domain.com/?page=credit [R=301,QSA,L]
I'm sorry I'm not too good at this. Any help I can get will be appreciated.
Thanks.
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} !=on
RewriteCond %{QUERY_STRING} (^|&)page=(credit|submit_form)(&|$) [NC]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTPS} =on
RewriteCond %{QUERY_STRING} !(^|&)page=(credit|submit_form)(&|$) [NC]
RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
I am writing a rewrite rule to redirect all urls from mysite.co.uk/en/ to mysite.co.uk/. I have the following I have written. Just would like someone to confirm it is correct for me and suggest possible improvements if any.
Options +FollowSymlinks
RewriteEngine on
RewriteOptions MaxRedirects=10
RewriteCond %{HTTP_HOST} ^(www\.)?mysite\.co\.uk$
RewriteRule ^en/(.*)$ http://www\.mysite\.co\.uk/$1 [NC,R=301]
RewriteCond %{HTTP_HOST} ^(www\.)?mysite\.com\.au$
RewriteRule ^en/(.*)$ http://www\.mysite\.com\.au/$1 [NC,R=301]
RewriteCond %{HTTP_HOST} ^(www\.)?mysite\.co\.nz$
RewriteRule ^en/(.*)$ http://www\.mysite\.com\.nz/$1 [NC,R=301]
RewriteEngine off
After much research turns out I should be able to do just this:
redirect 301 /en/ http://www.mywebsite.co.uk/
redirect 301 /en/ http://www.mywebsite.com.au/
redirect 301 /en/ http://www.mywebsite.co.nz/
This we redirect any urls that are going to www.mywebsite.co.uk/en/ or mywebsite.co.uk/en/ to www.mywebsite.co.uk/
Use below code
Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^domain.com [nc]
rewriterule ^(.*)$ http://www.domain.com/$1 [r=301,nc]
Please REPLACE domain.com and www.newdomain.com with your actual domain name.