I have the following .htaccess-File:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301]
This should change the prefix of the input always to http://www.example.com/something but this doesn't work and I don't know why not. It redirects only to www.example.com...
I have tried a lot but I couldn't find a solution. Could it be, that the browser doesn't display http://?
Related
In my .htaccess I have this lines:
RewriteEngine On
RewriteCond %{http_host} ^test.ru [nc]
RewriteRule ^(.*)$ http://www.test.ru/$1 [r=301,nc]
RewriteBase /
RewriteRule ^(.*)/$ index.php?string=$1 [NC,L]
so I want to change test.ru to www.test.ru
and also to give www.test.ru/my_string_value/ to $_GET['string']
(for example from this URL www.test.ru/ru/pages/id/) , exploding this ru/pages/888 , getting my parameters (lang=ru, cat=pages, id=888).
When I'm trying to check www adding part (writing test.ru must make www.test.ru) geting this:
http://www.test.ru/index.php?string=http://www.test.ru
With parameters getting is ok!
And one interesting thing! After comenting lines
#RewriteEngine On
#RewriteCond %{http_host} ^test.ru [nc]
#RewriteRule ^(.*)$ http://www.test.ru/$1 [r=301,nc]
#RewriteBase /
#RewriteRule ^(.*)/$ index.php?string=$1 [NC,L]
getting the same thing!
What is wrong.
You have some things in the wrong order but you are probably cached. The browser will cache 301 redirects. Clear your browser cache or try in another browser. Also use 302 while testing. Then change to 301 when everything is working. And you should use the L flag on redirects as well.
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^test\.ru [NC]
RewriteRule ^(.*)$ http://www.test.ru/$1 [R=302,NC,L]
RewriteRule ^(.*)/?$ index.php?string=$1 [NC,L]
from
cdn1.example.com
cdn2.example.com
cdn3.example.com
to
example.com
Please let me know how to redirect those?....
You could have provided more details and also what you have tried, anyways here you go:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(cdn1|cdn2|cdn3)\.example\.com
RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]
As a bonus, any eventual path and/or querystring is preserved, I guess you would need that.
EDIT : As you requested, here is a cdnx version:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^cdn[0-9]+\.example\.com
RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]
Here is my htaccess
Options -Indexes
<IfModule dir_module>
DirectoryIndex in.php
</IfModule>
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteRule \.(css|jpe?g|gif|png|js|css|htm|html|mp3|wav|ico)$ - [L]
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /([^/]+/)*[^.#?\ ]+\.php([#?][^\ ]*)?\ HTTP/
RewriteRule ^(([^/]+/)*[^.]+)\.php http://www.example.com/$1 [R=301,L]
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^some/(.*)/(.*)/$ test.php?z=$1&n=$2 [NC,L]
RewriteRule ^some/(.*)/(.*)$ test.php?z=$1&n=$2 [NC,L]
RewriteRule ^some/(.*)/$ test.php?z=$1 [NC,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !.*test.php$ [NC]
RewriteRule ^([^\.]+)$ $1.php [NC,L]
None of the $_POST with relative paths are working after implementing mod_rewrite.
Note :I have already set
< base href="http://example.com/"/>
and RewriteBase / as mentioned above
I have gone through other questions at SO but no luck!
Thanks for your advise!
I'm sorry.. Not working in the sense, POST variables are probably getting lost during htaccess redirects ???
I would validate the code you are using to build your form actions. I agree with the above commentors that you are losing your POST variables because of the redirect.
Why might this be happening?
First off, that rewrite rule to redirect from non-www to www should only happen the first time someone visits your website without the www's. You should program accordingly.
Ie - someone types in 'example.com' - your rewrite will take them to 'www.example.com'
From then on, if you must refer to your full domain in a form, use the entire WWW version.
<form action="http://www.example.com/processForm.php" method="POST">
Alternatively, you could stop using the full domain.
A common place I've seen this happen is when programmers use plugins that define a configuration object. Perhaps that configuration object is pointing to the non www version by accident. Imagine this code:
$config = array('domain'=>'example.com', 'othersettings'=>'more here');
Forms are sometimes created doing this:
<form action="<?php echo $config['domain'] ?>/processForm.php" method="POST">
See, that would get translated into the non-www version, losing your POST values.
Good luck!
My website is hosted on a VPS powered by Ubuntu with LAMP.
I can't use direct links to any page without www.
that is typing url http://example.com/secondpage will redirect to http://www.example.com/.
the second page had lost. But http://www.example.com/secondpage works perfectly.
I tried changing .htaccess, but no effect.
Can you help me?
You need to use this inside your .htaccess:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
If this doesn't work, you can use this:
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com [nc]
RewriteRule ^(.*)$ http://www.example.com/$1 [r=301,nc]
I need to redirect users accessing mysite.com to www.mysite.com in my .htaccess file.
The problem is anything I try won't work, I think because ^mysite.com doesn't exclude www.mysite.com so that will create a bad loop, but I usually get error 500.
I also need to exclude another subdomain, the img.mysite.com.
How can I do that?
I used many examples from the net & a few htaccess generators, which gave me this code:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^mywebsite.com[nc]
RewriteRule ^(.*)$ http://www.mywebsite.com/$1 [r=301,nc]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
This is what you need - taken from the default Drupal .htaccess
Try something like this:
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www.mywebsite.com$ [NC]
RewriteRule ^/(.)$ http://www.mywebsite.com/$1 [L,R=301]