I have a whmcs installation in a /whmcs and wanted to force https to my entire website, so i added a .htacess with this code below in the root of my website :
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
The problem is that whmcs have some issues when modifying something, and also my customers could not attach files on their tickets.
Their support told me to add a .htaccess in /whmcs to override the directives in the root .htacess
I tried many times without success, that's why i am here asking for help.
I have two choices :
1- adding a .htaccess to /whmcs to ignore the redirection made in the root .htacess.
2- modify the root .htaccess to ignore the /whmcs subfolder
Any help is welcome.
You can exclude the /whmcs folder from your rule as
RewriteEngine On
RewriteCond %{HTTPS} =off
RewriteRule ^(?!whmcs/) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,NC,L]
As the other response mentioned, you can try to exclude the rewrite from your whmcs folder, and this seems like a plausible solution.
Something you may want to check is in the WHMCS configuration itself. If in WHMCS > Setup > General Settings you have a non-SSL URL for your System URL and an SSL URL for your System SSL URL, you can get looping. To avoid this, if you are wanting to force SSL across the board, change your System URL to be https://yourdomain and hit save. WHMCS should set only the System URL, and every call to WHMCS will be SSL, and if not, WHMCS will handle the redirection.
Related
I have a domain with two versions and I need to redirect 1 of the versions
test.example.ca
test.example.ca/en
test.example.ca/fr
I need the first domain test.example.com to redirect to test.example.ca/en anytime someone hits it. but i don't want test.example.ca/fr to redirect to test.example.com/en/fr
this is what I've been trying with no success.
RewriteCond %{HTTP_HOST} =test.example.ca
RewriteCond %{HTTP_HOST} !=test.example.ca/fr
RewriteRule ^(.*)$ https://%{HTTP_HOST}/en/$1 [R=301,L]
I understand the question such that you simply to not want requests to https://test.example.com/fr... to get redirected. So you want an exception.
I'd say this roughly is what you are looking for:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^test\.example\.com$
RewriteCond %{REQUEST_URI} !^/fr
RewriteRule ^ https://test.example.ca/en%{REQUEST_URI} [R=301,L]
Chances are that your question was wrong in a few details, to me it reads as if you were not really precise with your host names. But above should be the correct answer to what you actually asked.
You should implement such rules in the http server's host configuration. If you do not have access to that you can also use a distributed configuration file (".htaccess"). That file should be located in the DOCUMENT_ROOT folder defined for your http host. And you need to make sure that the interpretation of such files is enabled at all (see the documentation for the AllowOverride directive for that).
It is a good idea to start out using a R=302 temporary redirection first. And to only change that to a R=301 permanent redirection once everything works as desired. That prevents nasty caching issues on the client side.
I'm new at programming. We have an office project, the website's URL is www.project.com.ph (sample name), this is already a live website from the client. But the released printouts have the instructions for the users to go to www.project.com/ph which is wrong and we can't reprint the material since it already reached plenty of event places.
Now the problem is, we need to redirect to www.project.com.ph automatically if the users type in the browser's address bar www.project.com/ph. I ask if this is possible without any kind of CMS or Wordpress and how to actually do it? We bought a new domain www.project.com for this. Any kind of help is appreciated.
Try the following near the top of your .htaccess file in the root of www.project.com. This works OK (although marginally less efficient) if both domains are pointing to the same place, since it specifically checks that we are requesting the "wrong" domain:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?project\.com$ [NC]
RewriteRule ^ph/?(.*) http://www.project.com.ph/$1 [NC,R=302,L]
This will redirect requests for www.project.com/ph (no slash), www.project.com/ph/ (with a trailing slash) and www.project.com/ph/<whatever> to http://www.project.com.ph/<whatever>.
This is a temporary (302) redirect. Change it to a permanent (301) only when you are sure it's working OK.
From kj.'s answer on a similar question, here
In your .htaccess for www.project.com, this should do the trick.
RewriteEngine on
RewriteRule ^(.*)$ http://www.project.com.ph/ [R=permanent,NC,L]
This will redirect any request to project.com to the domain http://www.project.com.ph/
To include the path after the /ph/` you can use this.
RewriteEngine on
# redirect including path after ph/ (e.g. project.com/ph/directory/file.php to project.com.ph/directory/file.php
RewriteRule ^ph/(.*)$ http://www.project.com.ph/$1 [R=permanent,NC,L]
# redirect any other requests to project.com.ph index
RewriteRule ^(.*)$ http://www.project.com.ph/ [R=permanent,NC,L]
You can redirect (301 redirect) the URL using RewritrRule in .htaccess file
RewriteRule "http://www.project.com/ph/(.*)" "http://www.project.com.ph/$1" [L,NC,R=301]
I have two domain names bought mainly for SEO, I want to redirect them to certain pages on website of a different domain name.
I know I need to redirect them with 301's in the .htaccess.
But I'm getting confused, do I need to create essentially 3 .htaccess files one on each domain?
Thanks
No, you only need one .htaccess file per domain. However, be wary of including or excluding the www. in your URL, as you may render your SEO useless.
Redirecting to a non www. URL:
This assumes you are using Apache or something similar.
Open your existing .htaccess file using a text editor, and append the following code to it:
Options +FollowSymLinks
RewriteEngine on RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^example\.com
RewriteRule (.*) http://example.com/$1
[R=301,L]
Where example.com/ is your domain. As far as I am aware, you can append any page to this URL with the same effect.
Redirecting to a www. URL:
Again, assuming Apache or similar:
Open your .htaccess file in the text editor, and append:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1
[R=301,L]
Again, example.com/ refers to your own domain. Again, AFAIK you can append specific pages without issue.
With most websites, www.example.com and example.com will take you to the same place. If you haven't made any changes to this, I would advise using the former example.
Additionally, if you are using Wordpress, there are a vast number of different plugins that can handle this for you. For example (and I am not recommending this over any other plugin), https://wordpress.org/plugins/simple-301-redirects/
You may also hear the coderel="canonical" or see it from time-to-time. Some SEO professionals actually recommend this over 301, however with modern browsers and modern crawlers, this should no longer be an issue.
I have a url that is www.blahblah.com/something
That is a remote service, I don't have anything to do with it.
How can I use .htaccess on my own server and rewrite from www.myurl.com so that the content displayed is all www.blahblah.com/something, but the address bar still reads www.myurl.com
No, this is not possible with foreign urls.
You can, however, do this locally. For example, look at this htaccess file:
RewriteEngine On
Options +FollowSymlinks
RewriteBase /
RewriteRule ^some/test/url$ index.php?some=test&or=url [L]
In this scenario, if you visit www.myurl.com/some/test/url it will show as such on the browser, but your server will actually be running index.php in your document root with the parameters some=test&or=url.
This is only possible for scripts running on your server. You cannot do this on another server/domain. If you try this (eg, by changing index.php?some=test&or=url in the example above to http://www.blahblah.com/something), then apache will just redirect the browser to that url.
htaccess (Apache) makes the connection to the user, and the user is expecting a response from YOUR server. If you try to load content from another server, Apache would have to make that connection, load the resulting HTML or whatever, and pass it back to you. But this gets messy, especially when you get into cookies, SSL, javascript, etc.
My question is: why do you actually need this? I'm not sure I understand why it is a problem if the user's url changes. If it's a service you have no control over, why is it so bad to just send them to it?
You might want to research more about cache servers, or using PHP to to make the http call to the server you want and "pass through" the content, assuming you know beyond a doubt there will be no issues with cookies or SSL or whatever. But again, why not just send them to the proper URL?
Try this:
RewriteCond %{HTTP_HOST} ^DomainA.com
RewriteRule ^(.*) http://DomainB.com/$1 [P]
It works for me.
Source: http://www.inmotionhosting.com/support/website/htaccess/redirect-without-changing-url
mod_rewrite is the right way.
Make sure it is mod_rewrite is activated in our apache conifiguration.
add to the .htaccess
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.blahblah\.com$ [NC]
RewriteRule ^(.*)$ http://www.myurl.com/$1 [R=301,L]
RewriteCond defines the condition. In this case if the http_Host is www.blahblah.com
RewriteRule defines what to do. In this case forward to your target domain. $1 is the rest of your URL
More Details you can find here: http://httpd.apache.org/docs/current/mod/mod_rewrite.html
I am redirecting one domain to another, but I want to preserve the path in the redirect. So for example, I want to visit www.example.com/services/education/page.html, but my redirect will bring them to www.new-example.com/services/education/page.html. What do I write in my .htaccess file to preserve the path "/services/education/page.html"?
Right now I have:
redirect 301 http://www.example.com/ http://www.new-example.com/
But I'm not sure if that works or not (Can't test yet as I am waiting for domain details etc). I just want to be sure when I put the site live. Is that right or am I way off base?
Thanks!
This should do it:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !new-example.com$ [NC]
RewriteRule ^(.*)$ http://new-example.com/$1 [L,R=301]
try adding the following to your .htaccess in the root of your example.com domain
RewriteEngine On
RewriteBase /
#for all requests to www.example.com
RewriteCond %{HTTP_HOST} ^www\.example\.com$
#redirect them to new-example
RewriteRule (.*) http://www.new-example.com/$1 [R=301,L]
Your original command uses the mod_alias Apache module, and it would work, though you may want to update it to:
Redirect 301 / http://www.new-example.com/
Removing the exact domain of the current (old) domain means all domains that point to that folder will be sent to the new domain, making that one-line script more robust.
The other answers use the mod_rewrite Apache module. If you have that also installed, that's fine to use, though it's 4+ lines of code compared to one. Additionally, mod_alias is part of the "base" package, so should be on all Apache servers, while mod_rewrite is an optional extension, so some might not have it.