I have a domain at OVH that links to my EC2 instance like this:
www.mysite.com --> 12.34.56.78/folder/
So everytime I type "www.mysite.com" in my address bar I end up on my website but the URL has been replaced to "12.34.56.78/folder/".
I'm currently trying to tweak a .htaccess file at the root of my server but it doesn't seem to work...
Here is the content of the file:
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www.mysite.com$
RewriteRule ^(.*)$ http://www.mysite.com/ [L]
Maybe I'm not looking at the right solution... Anyway if you can help me, I'll be grateful!
Cheers,
You are missing a couple of things that I added below
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.mysite\.com$
#$1 will include the original URI in the redirect, 301 for permanent
RewriteRule ^(.*)$ http://www.mysite.com/$1 [L,R=301]
Related
I cant figure out how to redirect all requests except my ip to a subfolder in .htaccess
I came up with
RewriteEngine On
RewriteCond %{REMOTE_ADDR} !=123.45.67.89
RewriteRule ^$ /coming-soon/ [L]
RewriteRule (.*) http://example.com/coming-soon [R=301]
But when i write in browser for example example.com/asdasdas it gives me
coming-soon/coming-soon/coming-soon/coming-soon/coming-soon/coming-soon/coming-soon/coming-soon
What i would like to achieve is when user enters anything that it redirects to example.com/coming-soon unless it is my IP. I did research on SO, but I always get stuck.
Also there is a folder in the root /coming-soon with images and fonts for that html
Any help would be appreciated
You can use this :
RewriteEngine On
RewriteCond %{REMOTE_ADDR} !=123.45.67.89
RewriteCond %{REQUEST_URI} !^/coming-soon [NC]
RewriteRule (.*) http://example.com/coming-soon [R=301,L]
Make sure to clear your browser cache or use a different browser to test this code.
I have a blog folder in the public_html folder on my server with godaddy.
The .htaccess (in public_html) :
RewriteEngine on
Options +FollowSymlinks -Multiviews -Indexes
RewriteBase /
RewriteCond %{HTTPS} on
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{THE_REQUEST} /blog/article\.php\?id=([^\s&]+) [NC]
RewriteRule ^ blog/article/%1? [R=302,L]
RewriteRule ^blog/article/([^/.]+)/?$ /blog/article.php?id=$1 [L,QSA,NC]
The page takes me to 404 page on my online host with godaddy but it works fine on localhost.
I also tried:
RewriteCond %{QUERY_STRING} (^|&)article\.php\?id=(.*)(&|$)
RewriteRule ^(.*)/article.php$ $1/article/%1? [NC,L]
but that didn't do anything.
Please help!
Figured it out. For anyone that might run into the same problem, here is the simple solution:
Make sure that your tag contains the real url.
What I did was, I put the custom url in the tag and godaddy was not recognizing it.
So what I did was
article 1
instead it should be
article 1
That way it will redirect to the custom url correctly.
Hope that helps!
After redirecting my client domain to my server i created rewrite rule in root folder .htaccess file to point domain to a subfolder1 (joomla website):
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?myclientdomain\.com$ [NC]
RewriteCond %{REQUEST_FILENAME} !/subfolder/
RewriteRule ^(.*)$ /subfolder1/$1 [L]
Everything worked fine but today i found out that i can access any other subfolder in my server by entering for example: myclientdomain.com/subfolder2 and what's worse google can index that and show it in search results.
If there is any way to redirect a domain in a way that I won't be able to access any other folder on my server?
I would really appreciate help as I searched throughout google for answer, my server tech support said that they don't really support these kind of problems (they only gave me a piece of code from above) and I don't really know anything about .htaccess rules and how it works.
Try this
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?myclientdomain\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/subfolder\/?(.*)?$
RewriteRule ^(.*)$ /subfolder1/$1 [L]
Change above rule to:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?myclientdomain\.com$ [NC]
# if current URI is not starting with /subfolder/ then route to /subfolder/
RewriteRule ^((?!subfolder1/).*)$ subfolder1/$1 [L,NC]
I got wordpress installed in /WP. So i browsed the web to find an example of a htaccess that can redirect the user from domain.se to domain.se/wp. So if anyone just types in the domain name then they will be redirected to the /wp folder.
This was the one i found and it works.
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ http://domain.se/wp/$1 [R,L]
Question is, is it ok like this or is this a bad solution?
I think your code should be the following :
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/wp
RewriteRule ^(.*)$ http://domain.se/wp/$1 [R,L]
I am pulling my hair out here.
I have created a landing page which is http://www.pps-supplements.com/samples
it works and you can access it fine - no problems.
If you type in the address bar:
pps-supplements.com/samples
it takes you to the home page which is not good and causing me to have a headache.
My website is working well for non www to www on home page and categories but not on cms pages.
I have read a few posts on here and tried their solutions which is to edit the htaccess file but it hasn't fixed it.
Does anyone have any ideas how I can resolve this issue??
Pretty please!
You could try this in your .htaccess file....
Be sure to add it above any other rewrite rules or conditions you may already have in your htaccess file.
<IfModule mod_rewrite.c>
RewriteEngine On
Rewritecond %{HTTP_HOST} !^www\.pps-supplements\.com [NC]
Rewriterule (.*) http://www.pps-supplements.com/$1 [R=301]
</IfModule>
This will redirect any domain that is not www.pps-supplements.com to the version with www's
Also very handy for using when pointing multiple domains at a site.
Also, be sure that the webserver is set-up to receive the non www version, as in that it is listening for that version, as well as for the version with www's.
For anyone else looking at the accepted answer and running into issues with it not working you may have other Rewrites in place that need to be stopped from executing.
You can stop further execution by including the "L" param.
Example:
Rewritecond %{HTTP_HOST} !^www\.domain\.com [NC]
Rewriterule (.*) http://www.domain.com/$1 [R=301,L]
I wanted to redirect from example.com/category/ to www.example.com/category/
and I found solutions:
turn off Auto-redirect to Base URL in backend
and use this code in .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
</IfModule>
For Magento Multistore-Setups:
Rewritecond %{HTTP_HOST} ^example\.com [NC]
Rewriterule (.*) http://www.example.com/$1 [R=301,L]