302 redirects being cached in firefox - .htaccess

So I have the following .htaccess file:
RewriteEngine On
RewriteCond %{HTTP_REFERER} ^https?://www.google.com [NC]
RewriteRule ^dir/file.html http://domain.tld/dir/index.html [L,R=302]
When I visit my site by clicking on it in the Google SERP it showsme dir/file.html. If I hit F5 to refresh it does the redirect. But then if I try to go to http://domain.tld/dir/file.html from dir/index.html I can't. I get 302 redirected, once again, to the index.
It's as though the browser is caching the 302 redirect when the only redirects it should be capturing are 301 redirects.
Any ideas?

Related

Redirect all pages containing a particular part to home using htaccess

Recently my site got hacked, and tons of pages were generated. Most of them end with strings like ?_t=77, ?_t=97, and ?_t=56 etc. Basically, the ?_t= part is common in all of them.
How do I create a .htaccess rule to redirect all the links with ?_t= to home?
Some redirects I've already created:
<IfModule mod_rewrite.c>
RewriteEngine On
Redirect 301 /profile/1320172681 /u/DanLiu
Redirect 301 /profile/387899125 /u/LuckyMaheshwari
Redirect 301 /profile/15379797 /u/manishchopra
Redirect 301 /profile/335596945 /u/MatthewNord
Redirect 301 /profile/94097446 /u/abhimanyu
</IfModule>
Thanks
With your shown attempts/samples, please try following htaccess rules. Please make sure to clear your browser cache before testing your URLs.
<IfModule mod_rewrite.c>
##making your Rewrite engine ON here.
RewriteEngine On
##Rewriting urls with ending with ?_t=digits to home page here.
RewriteCond %{QUERY_STRING} ^_t=\d+/?$ [NC]
RewriteRule ^ / [R=301,L,QSD]
##Rewriting home page url to index.php here.
RewriteRule ^/?$ index.php [QSA,L]
###put your rest of htaccess Rules from here onwards.
Redirect 301 /profile/1320172681 /u/DanLiu
Redirect 301 /profile/387899125 /u/LuckyMaheshwari
Redirect 301 /profile/15379797 /u/manishchopra
Redirect 301 /profile/335596945 /u/MatthewNord
Redirect 301 /profile/94097446 /u/abhimanyu
</IfModule>

301 Redirects -- old pages with /? at start not working (Joomla 3)

Our old site had all its urls starting with "/?" . I have now created a Joomla 3 site, and registered all the old urls with a 301 to the new in our htaccess. However, the 301 Redirects are not working....
e.g.
Redirect 301 /?old-page /index.php?option=com_content&view=article&id=78&Itemid=999
Instead, all my redirects go to our Home page.
Any suggestions?
thanks
Geoff
Try:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^old-page$
RewriteRule ^$ /index.php?option=com_content&view=article&id=78&Itemid=999 [R=301,L]

How to Permanent Redirect a Directory That No Longer Exists (via .htaccess)

I am having trouble redirecting an entire directory that no longer exists on our server.
All variations of the following are not working and I simply get a 404 Page Not Found.
.htaccess file looks like this:
redirect 301 /non_existent_directory/ http://my.website.com/existent_directory/
Is it possible to use the Redirect 301 directive for this? Or is this only solvable by mod_rewrite?
Thanks
I even tried:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?my\.website\.com\/non_existent_directory\/$ [NC]
RewriteRule ^(.*)$ http://my.website.com/existent_directory/ [R=301,L]
No luck...
From the Redirect documentation, I would say
Redirect 301 /non_existent_directory http://my.website.com/existent_directory
or
Redirect 301 /non_existent_directory /existent_directory
should work, provided you are allowed to use this in a .htaccess file. See also Troubleshooting .htaccess files. You should test without 301 though, to prevent caching of bad redirects by the client.
If this doesn't work, you can try a RewriteRule of course
RewriteEngine On
RewriteRule ^/?non_existent_directory(.*)$ /existent_directory$1 [R,L]
But this is equivalent to the above Redirect directive.

webpage redirects in IE, Chrome... not Firefox?

With firebug, grab the HTTP headers.. firefox gives 200 OK status.
Firebug in Chrome, tells me it is a 301 redirect.
The problem is that the page is not supposed to redirect. The htaccess only forces WWW..
Help!
That kind of .htaccess rule works by redirecting the request! The R=301 at the end means "redirect, sending http status 301"
btw the rule you have will redirect www.example.com to example.com. Perhaps you want the opposite:
RewriteCond %{HTTP_HOST} ^website.com [NC]
RewriteRule ^(.*)$ www.website.com/$1 [L,R=301]

.htaccess opencart redirect 301

I just migrate my site from asp to opencart. In .htaccess I would like to do some redirect so that my customer can use back the old link to access
inside .htaccess
redirect 301 /contact.asp http://www.example.com/index.php?route=information/contact_us
redirect 301 /downloads.asp http://www.example.com/downloads
For Contact Us that work perfectly, however, for the downloads url, it didn't work correct.
when I access to http://www.example.com/downloads.asp it will redirect to http://www.example.com/downloads?_route_=downloads.asp
and Opencart show it is page not found.
For the http://www.example.com/downloads we had set SEO friendly URL in the backend system.
We able to access with
http://www.example.com/information/downloads
http://www.example.com/downloads
but we not able to access with normal link
http://www.example.com/index.php?route=information/downloads
The folowing is my full .htaccess
# Prevent Direct Access to files
<FilesMatch "\.(tpl|ini)">
Order deny,allow
Deny from all
</FilesMatch>
# SEO URL Settings
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]
redirect 301 /contact.asp http://www.example.com/index.php?route=information/contact_us
redirect 301 /downloads.asp http://www.example.com/downloads
============ANOTHER TESTING========================
I did some testing on this on my localhost I found out it is a quit interesting result. However, my problem still haven't solve.
I run the .htaccess from http://localhost/example and http://example (added virtual directory)
For http://localhost/example
redirect 301 /example/downloads.asp http://localhost/example/downloads/
and
For http://example
redirect 301 /downloads.asp http://example/downloads/
Then I tried, redirect to my live version link, from localhost (http://example)
redirect 301 /downloads.asp http://www.example.com/downloads/
I access to http://example/downloads.asp
The browser redirect to me
http://www.example.com/downloads?route=downloads.asp
NOTED
In LIVE version, I did not added any redirect code [VERY SURE FOR THIS]
But in Live version, I am to access directly with enter
http://www.example.com/downloads
I am not sure why from localhost redirect 301 to live version will come out
http://www.example.com/downloads?route=downloads.asp
Any idea?
Solution Found:
.htaccess redirect 301 working with opencart v1.5.4.1
Additional code needed for... (and credits of this fix):
https://github.com/opencart/opencart/pull/142
... replace contents of:
- catalog/controller/common/seo_url.php
- system/library/url.php
Redirect Fine:
RewriteRule contacto http:....com/index.php?route=information/contact [R=301,L]
Redirect Not Working:
redirect 301 contacto http:....com/index.php?route=information/contact
Verified.
Put it in front of router. Also add $ after .asp and ^ in front.
# Prevent Direct Access to files
<FilesMatch "\.(tpl|ini)">
Order deny,allow
Deny from all
</FilesMatch>
# SEO URL Settings
RewriteEngine On
redirect 301 ^contact.asp$ http://www.example.com/index.php?route=information/contact_us
redirect 301 ^downloads.asp$ http://www.example.com/downloads
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]
Why don't you redirect contact to /information/contact_us instead of index.php?route=information/contact_us ?
You can try a "?" at the end of the redirect url if it is not present there like 2nd url(it worked for me) :
redirect 301 /contact.asp http://www.example.com/index.php?route=information/contact_us
redirect 301 /downloads.asp http://www.example.com/downloads?

Resources