Redirect .html but not .html?with=options - .htaccess

I'm currently using an .htaccess to get round a problem with a CMS, nothing major and an htaccess fix is tidy enough.
I'm currently using the format...
redirect 301 /pictures.html http://www.domain.com/gallery.html
The problem though this causes is that the CMS uses pictures.html?vars=here to select galleries and so the redirect breaks this part of it. Is there any way I can redirect pictures.html but not when it has variables attached?

For example, add something like
RewriteCond %{QUERY_STRING} ^$
before your rule.

You can redirect everyone except your webserver by detecting the IP address like so:
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REMOTE_HOST} !^123\.45\.67\.89
RewriteRule \.html$ /alternate_page.html [R=301,L]

Related

htaccess redirect to file except own IP

I'm having a bit of a trouble finding the right way to this:
I'm about to launch a site, www.domain.com, but it's not quite yet ready for the public eyes just yet. So I want to redirect all visitors (except myself) to www.domain.com/teaser.html.
How can I do this, so I keep the site content hidden from visitors, without creating a loop if I redirect base url? How would a htaccess string look like?
If I create something like this:
RewriteEngine On
RewriteBase /
RewriteCond %{REMOTE_HOST} !^xxx.xxx.xxx.xxx
RewriteRule .* /coming-soon.html [R=302,L]
It just create a loop. How can I do this without creating a loop?
As mentioned in this question.
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REMOTE_ADDR} !=123.45.67.89
RewriteRule index.php$ /teaser.php [R=301,L]

.htaccess make subdomain the main domain without moving

I have my website in a subdomain:
subdomain.mydomain.co.uk
Now, I don't want to move subdomain.mydomain.co.uk but I want to use .htaccess to set it so that when someone types: mydomain.co.uk the url still remains mydomain.co.uk but acually shows subdomain.mydomain.co.uk
How can I do this?
Try putting this:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^mydomain.co.uk [NC,OR]
RewriteRule ^(.*)$ http://subdomain.mydomain.co.uk/$1 [L,R=302,NC]
You could try doing an R=301, but beware of the dangers of using a 301 redirect. We had huge problems with our website at one point using 301 redirects as written about in this article: http://getluky.net/2010/12/14/301-redirects-cannot-be-undon/

.htaccess forward from one domain to a specific .html page

I know how to use .htaccess to forward everything in one domain to a new domain name. But in this case, I want everything from one domain to go to a specific .html page on a different domain. That's where I'm lost. I'm trying the following but it just redirects to a folder and the page in question is in that folder but obviously, I don't want people seeing the contents of that folder. Make any sense? So example.com needs to go to yyy.com/some-page.html
This is what I'm currently using:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} (www\.)?5\.xxxx\.com [NC]
RewriteRule ^(.*)$ http://www.1.yyy.com/$1 [R=301,L]
Try:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} (www\.)?5\.xxxx\.com [NC]
RewriteRule .* http://www.1.yyy.com/some-page.html [R,L]
You can also put a blank index.html page to the directory in question to mask its contents or
you can put index.php file with this code <? header ("location: http://www.1.yyy.com/some-page.html"); ?> that will redirect a user to the desired page.
$1 is a place holder for the 1st pattern match. So if you are rewriting domaina.com/someurl/, it is attempting to load domainb.com/someurl/. Swap the $1 with the actual page --- e.g. somepage.html and it should work. But unless both of these domains are pointing to the same files/directories, the rule seems a bit overcomplicated.
So how about just a simple redirect?
Try this in your .htaccess file.
redirect 301 / http://somesite.com/somepage.html
OR you can try this.
RewriteRule ^(.*)$ http://somesite.com/somepage.html [R=301,L]
It does work and you can test my RewriteRule below.
http://htaccess.madewithlove.be/
There must be something else going on.

301 redirect with .htaccess - redirect if www is included or not

I've got the following 301 redirect in my .htaccess
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^old-site\.com,$ http://www.new-site.com/? [R=301,NE,NC,L]
If i visit
old-site.com
I am redirected correctly.
However, if I visit www.old-site.com, then it doesn't work.
Is there a way of effectively ignoring the www
Edit
There are several entries like this...
for example:
www.old-site.com/page-a-242.html to www.new-site.com/page-a
RewriteRule ignores the domain, so your first rule could be just
RewriteRule ^$ http://www.new-site.com/? [R,L]
For the other specific mappings you might use RewriteMap. See txt: Plain text maps for details on how to use it.
The drawback with RewriteMap is, that it can only be used in the main server config or in a virtual host environment.

How do I fix old links after modifing .htaccess for Joomla installation in a subfolder?

I have my main Joomla installation in a subdirectory. I used to redirect users from www.mysite.com to www.mysite.com/subdir with a 301 so that the live site was entirely dislocated over there.
I don't actually like the fact that all the URL are preceded by the subdirectory /subdir/ (and I also think this is not very good for SEO) so I modified my .htaccess file like this:
RewriteEngine On
RewriteBase /
# Add trailing slash if path does not contain a period or end with a slash
RewriteCond %{REQUEST_URI} !(\.|/$)
RewriteRule (.*) http://www.mysite.com/$1/ [R=301,L]
#Change http://yoursite.com to http://www.mysite.com (Optional)
RewriteCond %{HTTP_HOST} ^mysite.com$
RewriteRule ^/?(.*)$ http://www.mysite.com/$1 [R=301,L]
#Rewrites http://www.mysite.com/subdir to http://www.mysite.com/
RewriteRule ^(.*)$ subdir/$1 [L]
I also edited the configuration file for Joomla! so that now all the links in the site point (correctly) to www.main.com/theirquery and noto to www.main.com/subdir/theirquery
Now, however, all the old links (that have been posted to other webistes, for example) appears to be broken (404): how can I solve this?
I think I have to redirect (301) them to the new subdirectory-free address, that will be (another time) silently redirected with the htaccess I posted.
But I don't know how to do this!
Thank you in advance!
Can you try setting the $live_site parameter in configuration.php? You need to edit it directly rather than through the backend of Joomla.
You need to add this to your htaccess.
RewriteRule ^subdir/(.*)$ /$1 [R=301,NC,L]
This is not possible since the old links where not physical but stored in a database, so redirecting them wouldn't be possible without passing through the database again.

Resources