We had out customer request to redirect their custom url to specific page in the webshop directory, for that we setup a rewrite rule with rewrie condition as shown below
RewriteCond %{HTTP_HOST} abc.xxx.com$ [NC]
RewriteRule ^/$ /online/index.php3?shopid=111 [R]
RewriteCond %{HTTPS_HOST} abc.xxx.com$ [NC]
RewriteRule ^/$ /online/index.php3?shopid=111 [R]
As shown in above rules and condition the request coming from abc.xxx.com will be redirected to the web page in the webshop id 111 and it worked successfully
After few weeks the same customer had another request to add another URL for redirection for differn webshop ID 112
I used the similar rewrite rule and condition replacing the new URL and webshop id, and added it below the old rewrite condition and rules and restarted the apache but when i tested the new URL it was redirecting to shop ID 111 instead of 112.
RewriteCond %{HTTP_HOST} def.xxx.com$ [NC]
RewriteRule ^/$ /online/index.php3?shopid=112 [R]
RewriteCond %{HTTPS_HOST} def.xxx.com$ [NC]
RewriteRule ^/$ /online/index.php3?shopid=112 [R]
Later I had some work around and changed the order,I put the new rewrite rules and conditions first i.e ahead of the old rules and it worked perfaclty fine.
Does anybody have idea about this characteristic of the rewrite rules?
Related
I want to redirect any request to the root of my site to an anchor on the index. So
https://example.com/foo
Gets sent to
https://example.com/#foo
I've written this .htaccess file (it also redirects http requests to https, that part works, but is included for completeness)
RewriteEngine On
RewriteRule ^/(.*) /#$1 [NE,R=302]
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Based on the discussion in this thread: mod_rewrite with anchor link this should work, but it's not matching for some reason. I tried out the rule given in that thread using this tool: http://htaccess.madewithlove.be/ and it doesn't seem to work there either.
I've tried clearing my cache and accessing in incognito mode, to no avail. Any help?
We are looking for a solution for our htacces rewrite and have been looking all over the internet and could not find the solution. We have a multishop with 10 shops and are now going over at https and first want to test one shop and then do the others. We have set everything up correctly, but do not get the 301 redirect to work.
We have tried the following code:
RewriteCond %{HTTP_HOST} ^domain\.be$ [OR]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://www.domain.be/$1 [R=301,L]
But with this code all pages of the other webshops will also be redirected to this domain. Can someone help us setting it up so we can start transfer to https?
You need to remove the OR.
RewriteCond %{HTTP_HOST} ^domain\.be$
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://www.domain.be/$1 [R=301,L]
If you have split each of your domains to have independent vhosts (likely) and therefore utilize a separate block for SSL and HTTP, you should think about using a Redirect 301 in the HTTP section of the vhost to reduce complexity.
I am implementing the boost module for Drupal on my site and have run into this caching problem. The site caches pages but when visiting as an anonymous user it gives me the wrong cached pages. I am based in Ireland and expect to see the Irish version of the site but once the home page is cached it gives me the american version of the site.
Here is a list of steps I took to implement Boost
First I go to /admin/config/development/performance and disable "Cache pages for anonymous users"
Then I enabled "Boost" and "Boost Crawler" on the modules page
I go to .HTACCESS and disable "Bypass the boost cache for ssl requests" because the live site has https.
I generate the .HTACCESS and insert it into the correct place in my own .HTACCESS file
I have a feeling that I may have to write some custom code in the .HTACCESS file to get it to work but would really like some more incite before I go ahead and to that.
Currently the uncached version of the site is served up correctly in each country but is very slow.
So to summarise really what I need Boost to do for me is cache something like 200 versions of the site (thats how many countries we are serving the site to) and to serve the correct versions of the site to those countries. Is this possible and how can I implement it?
Any help is very much appreciated, Thanks.
Update 1
after adding the code here to .HTACCESS
RewriteCond %{HTTP:Accept-Language} ^et.*$ [NC]
RewriteCond %{REQUEST_URI} ^/$ [NC]
RewriteCond %{QUERY_STRING} !(^q\=) [NC]
RewriteRule ^(.*)$ /et [L,R=302]
RewriteCond %{HTTP:Accept-Language} ^fi.*$ [NC]
RewriteCond %{REQUEST_URI} ^/$ [NC]
RewriteCond %{QUERY_STRING} !(^q\=) [NC]
RewriteRule ^(.*)$ /fi [L,R=302]
and visiting the site form several different proxies I get it to cache in its country but the problem now is that it just caches the 1st country an anonymous visitor comes form.
My home page is in cache/normal/SITES_NAME/en_.html it doesn't seem to matter what site I come from Brazil, Germany, America, South Africa or Ireland it just caches the first one in en_.html and serves that to everywhere when really it needs to create a new set of cache files for each of these countries.
I've been using geopeeker.com and different proxies to view the pages from different parts of the world.
If you are using path prefix to detect language, Boost will not work.
You have to add this in your .htaccess to fix the problem.
RewriteCond %{HTTP:Accept-Language} ^et.*$ [NC]
RewriteCond %{REQUEST_URI} ^/$ [NC]
RewriteCond %{QUERY_STRING} !(^q\=) [NC]
RewriteRule ^(.*)$ /et [L,R=302]
RewriteCond %{HTTP:Accept-Language} ^fi.*$ [NC]
RewriteCond %{REQUEST_URI} ^/$ [NC]
RewriteCond %{QUERY_STRING} !(^q\=) [NC]
RewriteRule ^(.*)$ /fi [L,R=302]
This link provides further information.
I have a site built in codeigniter. We use short urls from our database & rewrite rules to redirect them to their full path.
For example,
RewriteRule ^secure-form$ form/contract/secure-form [L]
This works fine by itself. But I would like to use SSL on certain pages. I have edited the code so that if you go to one of these pages, all instances of http:// within the page are replaced with https:// but I need to rewrite the url to use it as well.
The pages all use the same template and all the content comes from the database so I can't just specify ssl on a particular directory.
The url's for the secure pages all start with 'secure' so I wrote the following rules and placed them above the other rewrites.
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} ^/secure/?.*$
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} !^/secure/?.*$
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1 [R=301,L]
RewriteRule ^secure-form$ form/contract/secure-form [L]
RewriteRule ^secure-different-form$ form/contract/secure-different-form [L]
all other rewrite rules for specific pages follow
then the default rewrite further down...
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
The problem is that when I add the rules to change the protocol, it ends up displaying 'form/contract/secure-form' in the url instead of 'secure-form'.
This renders the actual form on the page broken since it uses that url to build itself.
If I take out the rules that change the protocol, it displays secure-form in the url as it should, but the page is not secure.
What am I doing wrong?
----UPDATE----
Ooh, after over 20 hrs of searching, I think I finally have an answer. So, first time through, https is off & gets turned on. Then, because of the 301, it's run again & the page gets sent to form/contract/secure... But this time, https is on. Since the uri no longer STARTS with secure, it turns https off.
Hopefully, this will help someone else.
I know this issue has been addressed in many ways, but couldn't find any similar to this one I have now. The thing is that I have a code to force https to a certain or a particular url, but it seems that the (s) letter can be removed by hand so the url goes with http instead!! I mean I want the https to be force again in case the url is changed from https to http.
I hope it is a clear explanation.
RewriteCond %{SERVER_PORT} 443
RewriteCond %{REQUEST_URI} main
RewriteRule ^(.*)$ https://www.domain.com/folder1/folder2/login$1 [R,L]
does this code redirect again in case https is changed??
Thanks
Update #1
I got the meaning of what I want to point out to. It is called "blocked crawling of https"
Do this:
RewriteCond %{REQUEST_URI} main
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://www.domain.com/folder1/folder2/login$1 [R,L]