redirect not working with .htaccess - regex

I have this in my htaccess
Options +FollowSymlinks
RewriteEngine On
Deny from all
#RewriteRule (.*) http://google.com [R=301,L]
Allow from 127.0.0.1
Allow from 89.32.93.99
RewriteRule index.php$ /otherfolder [R=301,L]
I am trying to redirect all the requests to a new folder but for some reason the above does not work.
I have also tried
Redirect 301 / /otherfolder
but that just added other folder again and again to my domain like this
mydomain.com/otherfolder/otherfolder/.....
thanks

Keep your rules like this:
Deny from all
Allow from 127.0.0.1
Allow from 89.32.93.99
Options +FollowSymlinks
RewriteEngine On
RewriteRule ^(index\.php)?$ /otherfolder [NC,R=301,L]
^(index\.php)?$ will match either / or /index.php in URL.

Related

Htaccess redirect from http to https and get params

I need to redirect this:
http://www.mysite.com/pages/addtocart.php?id=XXXX
to this
https://www.mysite.com/checkout/cart/addsku?id=XXXX
Up to now, this is what I have:
RewriteRule ^/pages/addtocart.php?(.*)$ https://www.mysite.com/checkout/cart/addsku?$1 [R=301,L]
But it's not working.
Help?
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your DOCUMENT_ROOT/.htaccess file:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} off
RewriteRule ^pages/addtocart\.php$ https://%{HTTP_HOST}/checkout/cart/addsku [L,R=302,NC]
PS: Query Parameter will automatically be carried over to new URL.

How to redirect to other host using mod_rewrite in Apache

I need to create Rewrite Rule for mod_rewrite in Apache but it's really hard for me to understand this whole syntax.
I have links such as:
http://www.example.com/0001/images/image1.gif
and I need them to redirect it to completely other server like:
http://127.127.127.127/0001/images/image1.gif
Is this achievable?
On example.com 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\.)example\.com$ [NC]
RewriteRule ^ http://127.127.127.127%{REQUEST_URI} [R=301,L]

not able to redirect HTTP to HTTPS using rewrite in htaccess

I have tried url redirection of HTTP to HTTPS on my website by using several different solutions in .htaccess and none have worked.
Well, actually it does work if I type in directly:
(only for example) http://mywebsite.com
into the browser address bar....but if I try to redirect the url any other way, it won't work. If I try the link to my page listed on Google http://mywebsite.com/ it will not redirect to https://www.mywebsite.com. I need it to redirect from HTTP to HTTPS if someone clicks the link to my page from a search engine.
So far I have tried:
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]
then I tried...
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]
and then I tried...
RewriteCond %{SERVER_PORT} !443
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R,L]
None worked. What else should I try? (this website is being hosted on a web hosting service site that has uses an apache web server). Also, I have an SSL certificate for the page, if that makes any difference.
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} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
Tip: Clear your browser cache or use a different browser to test.

htaccess RedirectMatch regular expression for URL?

On my Wordpress blog, I used to have a plugin that I no longer need. The plugin used to create a bunch of URLs that looked like this:
http://tambnguyen.com/manage-subscriptions?srp=532&sra=s
with the postID being 532. How do I redirect the query strings so that the above URL will redirected to:
http://tambnguyen.com/?p=532
I've tried a few method without any luck (there's an optional "/" after "manage-subscriptions"
<IfModule mod_rewrite.c>
RedirectMatch 301 ^/manage-subscriptions/?\?srp=(\d{1,5})(.*)$ http://tambnguyen.com/\?p=$1
</IfModule>
Please help. 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 %{QUERY_STRING} ^srp=([^&]+) [NC]
RewriteRule ^manage-subscriptions/?$ /?p=%1 [L,R=301,NC]

Redirect all traffic to root of another domain

I have a domain that's not to be used anymore. I want to redirect all from http://www.old.com/ to http://www.new.com/, no matter what page the user's attempted to access on www.old.com.
Doing this:
RewriteEngine on
Redirect 301 / http://www.new.com/
is fine for the root, but other pages would do this:
http://www.old.com/cms -> http://www.new.com/cms
whereas I'd want it to go to the root, no matter what.
From http://www.webconfs.com/how-to-redirect-a-webpage.php I'd say you can use the following configuration
Don't redirect subfolders/files (as you wanted): www.example.com/demo/ -> www.newexampledomain.com
Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) http://www.newdomain.com/ [R=301,L]
Redirect to subfolders/files: www.example.com/demo/ -> www.newexampledomain.com/demo/
Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) http://www.newdomain.com/$1 [R=301,L]
Put this code in your ROOT .htaccess on www.old.com
Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?old\.com$ [NC]
RewriteRule ^ http://www.new.com/ [R=301,L]
This rule will externally redirect all www.old.com/* to www.new.com/