I want to be able to redirect this URL:
www.shorturl.co.uk/answers
To this URL:
http://actual.url.co.uk/answers.html
I have tried the following in .htaccess but it doesn't appear to be working:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.shorturl\.co.uk$ [NC]
RewriteRule ^answers$ http://actual.url.co.uk/answers.html [L,R=301,NC]
Can anyone point out where I might be going wrong? Thanks
I'm not an expert in this, but you could give it a try:
RewriteCond %{HTTP_HOST} ^www\.shorturl\.co\.uk$ [OR]
RewriteCond %{HTTP_HOST} ^shorturl\.co\.uk$
RewriteRule ^answers$ http://actual.url.co.uk/answers.html [R=301,L]
Related
I am trying to do two things here:
redirect to a sub-folder
redirect http://www.something.com/some/page.html
or
https://www.something.com/some/page.html
to
https://www.something.com/subfolder/some/page.html
redirect http to https
redirect
http://www.something.com/subfolder/some/page.html
to
https://www.something.com/subfolder/some/page.html
And I want to do both of them in the same .htaccess file
I have been able to redirect to subfolder by the following code:
Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} something.com [NC]
RewriteRule ^(.*)$ https://www.something.com/subfolder/$1 [R=301,NC]
And then I am trying to do both of them; i.e. http to https(only if http request comes) and redirect to subfolder by the following code:
Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteBase /
RewriteCond %{HTTPS} !=on
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R,L]
RewriteCond %{HTTP_HOST} something.com [NC]
RewriteRule ^(.*)$ https://www.something.com/subfolder/$1 [R=301,NC]
But it's not working.
What am I doing wrong here?
EDIT
When using #starkeen's solution; i.e.
Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteBase /
RewriteCond %{HTTPS} off
RewriteRule ^ https://www.example.com%{REQUEST_URI} [NE,L,R]
RewriteCond %{REQUEST_URI} !^/subfolder
RewriteRule ^(.*)$ https://www.example.com/subfolder/$1 [R=301,NC,L]
I am expecting the following as result:
https://www.example.com/subfolder/brands/omega.html
when I give any of the following:
http://example.com/brands/omega.html OK
https://example.com/brands/omega.html OK
http://www.example.com/brands/omega.html OK
https://www.example.com/brands/omega.html OK
http://example.com/subfolder/brands/omega.html WRONG
http://www.example.com/subfolder/brands/omega.html WRONG
But the last two are redirecting to
https://www.example.com/subfolder/
Here is a rule to do both the tasks in a single rule:
RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{REQUEST_URI} !^/subfolder [NC]
RewriteRule ^(?:subfolder)?(/.*)?$ https://www.example.com/subfolder$1 [NE,L,R=302,NC]
Make sure to clear your browser cache before testing this rule.
Try :
Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteBase /
#--Http ==>https--#
RewriteCond %{HTTPS} off
RewriteRule ^ https://www.example.com%{REQUEST_URI} [NE,L,R]
#--exclude the destination to avoid redirect loop--#
RewriteCond %{REQUEST_URI} !^/subfolder
#--redirect /foo to /subfolder/foo--#
RewriteRule ^(.*)$ https://www.something.com/subfolder/$1 [R=301,NC,L]
Clear your browser'cache before testing this redirect.
I am looking to one domain to another with all sub-urls as well. The original url would be ehanceinsdev.com and the redirected url would be www.enhanceinsurance.com. I would want it so that enhanceinsdev.com/foo would go to www.enhanceinsurance.com/foo.
Thanks for your help!
You can use this simple rule in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^enhanceinsdev\.wpengine\.com$ [NC]
RewriteRule ^ http://www.enhanceinsurance.com%{REQUEST_URI} [R=301,L,NE]
Try
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^ehanceinsdev\.com$ [NC]
RewriteRule ^(.*)$ http://www.enhanceinsurance.com/$1 [R=301,L]
trying to redirect this query to a new domain:
www.domain.com/search.php?q=keyword
to
www.newdomain.com/search.php?q=keyword
keyword can be any word
And want to keep the rest in domain, I just need to redirect this query.
I try several ways and the one I found closer to solution is this one:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^q=1$
RewriteRule ^search\.php$ http://www.newdomain.com/search.php?q=$1 [R=301,L]
but does not work!
Hope someone could help me correcting this and also if this is the best way to do the job?
Many thanks.
You're pretty close.
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 %{HTTP_HOST} ^(www.)?domain\.com$ [NC]
RewriteCond %{QUERY_STRING} ^q=.+ [NC]
RewriteRule ^(search\.php)$ http://www.newdomain.com/$1 [R=301,L,NC]
Try this
RewriteEngine On
RewriteCond %{QUERY_STRING} ^id=123$
RewriteRule ^/?product\.php$ http://website.com.au/product_123.php? [L,R=301]
Or
RewriteEngine On
RewriteCond %{QUERY_STRING} ^id=([^&]+)
RewriteRule ^/?product\.php$ http://website.com.au/product_%1.php? [L,R=301]
this works and is simple
RewriteEngine on
RewriteRule ^(.*)$ http://newdomain.com/$1 [QSA]
With .htaccess how can i redirect:
http://localhost/mvc_md/index.php/welcome/destroy
to
http://localhost/mvc_md/welcome/destroy
I'm currently using this and it isnt working:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^localhost/mvc_md/$
RewriteRule ^(.*) localhost/$1 [QSA,L,R=301]
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^([a-zA-Z]*)/?([a-zA-Z]*)?/?([a-zA-Z0-9]*)?/?$ index.php/$1/$2/$3 [NC,L]
Can someone please provide me with the proper directives in .htaccess file to have www.host.com requests to be redirected to host.com and vice versa?
This will redirect from http://www.yoursite.com to http://yoursite.com:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^yoursite\.com
RewriteRule (.*) http://yoursite.com/$1 [R=301, L]
And this is the reverse:
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{http_host} ^yoursite.com [NC]
RewriteRule ^(.*)$ http://www.yoursite.com/$1 [R=301,L]
The above is what I use on my server, and it works perfectly.