.htaccess changes blocked by cache? - .htaccess

I read everywhere that .htaccess isn't stored in the browser's cache. But I made changes (RewriteRule) which don't work in Chrome (my standard browser) but when I use inkognito-mode or a different browser it works fine. How is that possible and how can change it, that people will see the changes? My code:
RewriteCond %{HTTP_HOST} ^www.aaa.com$
RewriteRule (.*)$ http://www.bbb.com/cms/index.php/abc [R=301,L]
thanks!

Related

.HTACCESS RewriteRule force default page to HTTP

I did a lot of searching on this, and just couldn't quite find the right answer. A lot of things got me close, but nothing worked like I wanted it to.
I'm working on a site where, because of an external JQuery add-on library, I need to force certain pages to be HTTP. Certain other pages (for shopping, etc) need to be HTTPS.
So far in my .HTACCESS file I have:
RewriteCond %{SERVER_PORT} !^80$
RewriteRule ^(index|event)\.php$ http://www.example.com%{REQUEST_URI} [R=301,L]
This works perfectly when the user goes to
https://www.example.com/index.php
But doesn't redirect when they go to
https://www.example.com/
Any suggestions on how to catch that last instance?
Thank you in advance!
To match landing page tweak your regex to match empty URI also like this:
RewriteCond %{SERVER_PORT} !^80$
RewriteRule ^((index|event)\.php)?$ http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NC,NE]

htaccess redirect old URL to new URL

On my website for SEO purpose the link to hotel.php?hotel_id=104 is changed to parkgrand.html
and changed htaccess to refer to the same script
code : RewriteRule ^parkgrand\.html$ /hotel.php?hotel_id=104
Till this it works fine. But I want if some user still accesses the old url i.e. hotel.php?hotel_id=104 then he should get automatically redirected to parkgrand.html and user agent should get a response 301
So, the code now becomes
RewriteCond %{REQUEST_URI} ^/hotel.php
RewriteCond %{QUERY_STRING} ^hotel_id=104
RewriteRule ^hotel.php /parkgrand.html [L,R=301]
RewriteRule ^parkgrand\.html$ /hotel.php?hotel_id=104
But this is causing a redirect loop and the intended page doesn't gets displayed to the user.
Can anyone tell me what should be the correct code for this.
Give this a try:
# Redirect /hotel.php?hotel_id=104 to /parkgrand.html
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+hotel\.php\?hotel_id=104[&\s] [NC]
RewriteRule ^ /parkgrand.html? [R=302,L]
Change from R=302 to R=301 once you confirm it is working to avoid caching.
Keep in mind you may have been cached from your previous attempts since you're using R=301, I will recommend you to test the above using a different browser to make sure its working in case your usual browser is cached.

htacces - need to fix broken links coming from other sites to mine

I am having an issue where Google Webmaster Tools is reporting a ton of 404 links to my site which are coming from ask.com.
I have tried to get ask.com to fix their side but of course they are not, so now I am stuck with over 11k of bad links to my site which I am suspecting is effecting my ranks right now.
Anyways I have a possible way to 301 them, but not sure how to do it with .htaccess.
Here is the bad link pointing to my site
http://www.freescrabbledictionary.com/sentence-examples/fere-film/feverous/about.php
It should be
http://www.freescrabbledictionary.com/sentence-examples/fere-film/feverous/
Besides the about.php there are other variations of endings as well, I basically need to be able to remove the ending.
Problem is that the URL after /sentence-examples/ can change. The beginning is always:
http://www.freescrabbledictionary.com/sentence-examples/
So basically:
http://www.freescrabbledictionary.com/sentence-examples/<-keep but can change->/<-keep but can change->/<-remove this->
This .htaccess should be placed on the folder before sentence-examples:
RewriteEngine on
# Redirect /sentence-examples/anything/anything/remove to /sentence-examples/anything/anything/
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(sentence-examples/[^/]+/[^/]+)/.* [NC]
RewriteRule ^ /%1/? [R=302,PT,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/(.*)$ /sentence-examples/examplesentence.php?havethis=$1&word=$2 [L]
Change 302 to 301 once you confirm it's working as expected.
If you have a CMS installed you might need a different rule to work along with it without conflicting.
Keep in mind that if you had previously tried different redirects using 301 aka permanent redirect its recommended that you use a different browser to test this rule to avoid the caching.
This is possibly quick and dirty but I've done a simple test on localhost and here just to make sure it works.
RewriteEngine On
RewriteRule ^sentence-examples/(.*)/(.*)/(.*)\.php http://www.freescrabbledictionary.com/sentence-examples/$1/$2/ [R=301,L]
You can see that I've added wildcard groups (.*) to the RewriteRule so that we can pick up the elements of the URL that we need to aid in proper redirection i.e. $1 and $2. You can also use the third one ($3) to get which destinations are being targeted alot for your SEO needs.
NB: The rule above assumes that that the redirected URL will always be from a .php target and to ensure that you can redirect regardless of whatever comes after the 3rd URL segment replace the RewriteRule with this
RewriteRule ^sentence-examples/(.*)/(.*)/(.*)$ http://www.freescrabbledictionary.com/sentence-examples/$1/$2/ [R=301,L]

too many redirect occurred when accessing from mobile browser

I am using wprdpress plugin WPtouch for the responsive website. When i open mobile page it redirect many times so it could not able to shoe result.
I am trying to make changes on .htaccess file but still not reaching on result.
here is my .htaccess code
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} "android|blackberry|ipad|iphone|ipod|iemobile|opera mobile|palmos|webos|googlebot-mobile" [NC]
RewriteCond %{HTTP_HOST} !^www.xdsavings.com/mobile-app
RewriteRule ^(.*)$ http://www.xdsavings.com/mobile-app/ [L,R=302]
Are you sure HTTP_HOST contains a path? Because if not, your condition won't prevent it from redirecting over and over again.
It seems like you should be using REQUEST_URI and checking for /mobile-app, or something to that order...
On a separate note as a smartphone and tablet user, I'd add that being served a subpar, dumbed down version of a site on those perfectly capable devices yields terrible user experience. If you really want a mobile version of your site, use a responsive html/css design with #media queries as appropriate.

How can I make my website redirect to another based on a cookie with .htaccess?

I'm trying to do this with .htaccess. So what I did was set a cookie named "domain" with the website I'm redirecting to. In my .htaccess file I have this
RewriteEngine on
RewriteCond %{HTTP_COOKIE} domain=([^;]+) [NC]
RewriteRule ^(.*)$ %1/$1 [L]
I got that code from a Google search. It's supposed to reditect http://mywebsite.com/something to http://someotherwebsite.com/something. But it's not working. Any tips?
Edit: I still haven't been able to get it to work. A temporary solution I'm using is using PHP to get the cookie value and redirect that way.
I would turn on RewriteLog on a fairly high level and see whether that provides a clue.

Resources