Helicon isapi rewrite 3 redirectcondition fails - url-rewriting

We have a url that makes use of a rewritemap to retrieve a parameter for the querystring in order to get the right themepage. This works wel and it shows the right themepage in the default language.
If a user wants to change the language of this thempage he will perform a redirect to the same url but a language parameter will be added to the url.
The problem is that it does not rewrite to the themepage but it gets rewritten to our homepage instead of the themepage.
A url like www.mysite.co.uk/theme/cars will be rewritten to www.mysite.co.uk/themepages/themepage.aspx?pgid=1
adding the language parameter : www.mysite.co.uk/theme/cars?lng=2 should redirect to www.mysite.co.uk/themepages/themepage.aspx?pgid=1&lng2 instead it is rewritten to the homepage. The url in the address bar is correct. So the rewriterule has to be incorrect.
This is part of my httpd.conf
<VirtualHost www.mysite.co.uk>
RewriteEngine on
AllowOverride all
RewriteBase /
RewriteMap thememap txt:C:\rewritemaps/redirectmap.txt [NC]
RewriteCond %{QUERY_STRING} ^$ [OR]
RewriteCond %{QUERY_STRING} ^lng=(.*)$ [NC]
RewriteRule ^theme/([^?/]+)\.* /themepages/themepage.aspx?pgid=${thememap:$1} [NC,QSA,L]
</VirtualHost>
Does somebody have a clue why this happens ?

Related

How to set a RewriteCond for a certain page URL

I have implemented a mod rewrite condition as shown below. Basically I want everyone other than me (from the stated IP address) to be redirected to a certain page on my site. That part works but these directives end up causing endless redirects and the browser times-out.
What might a RewriteCond directive look like to test the page /index.html and not do anymore rewrites if the page is https://example.com/index.html?
# 2016-03-18 redirect everyone except listed IPs
# 123.456.789.012 = my static Work Office address
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REMOTE_ADDR} !^(123\.456\.789\.012)$
RewriteRule ^(.*)$ https://example.com/index.html [R=302,L]
You have to exclude the destination you are redirecting to :
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REMOTE_ADDR} !^(123\.456\.789\.012)$
RewriteCond %{REQUEST_URI} !^/index\.html
RewriteRule ^(.*)$ https://example.com/index.html [R=302,L]
Otherwise you will get a redirect loop error because index.htm also matches the pattern ^(.*)$ .

Apache rewrite : how avoid to display url parameter when the url final slash is omitted?

In my .htacess of my domain, I must point subdomain to the 1rst GET parameter of the domain. The subdomain represents the language (for example en., fr, etc...).
In order to achieve this aim, here the rewrite code in the .htaccess :
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(.*)\.example\.com$ [NC]
RewriteRule ^(.*)$ $1?lang=%1 [NC,L]
I create a directory named test. This directory contains just index.html file.
So when you type in the url bar of a browser en.example.com/test/,
the rewrite code works.
But if you type en.example.com/test without the final slash, it redirects to en.example.com/test/?lang=en => it's a problem.
So have you an idea to correct that ?
Thank you in advance, cordially.
When specifying xx.example.com/test/, an internal redirect
occurs to xx.example.com/test/?lang=xx. The client never sees the ?lang=xx.
However, when specifying xx.example.com/test, where test is a directory,
mod_dir steps in and rewrites the URL to xx.example.com/test/, but in
such a way that the rewrite rule for the ?lang=xx redirect becomes public,
having the client see xx.example.com/test/?lang=xx as the URL - which is unwanted.
In order to keep the '?lang=' redirect local (hidden from the client)
place this in the .htaccess, BEFORE the original rewrite rules:
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.+[^/])$ $1/ [R,L]
The condition checks whether the requested filename is a directory,
and the rule forces a client-side redirect [R], so that a client requesting xx.example.com/test will be redirected to xx.example.com/test/.
The key however is the [L], which makes this rule the Last, preventing the following rules from executing. Without this L flag, the entire redirect from xx.example.com/test to xx.example.com/test/?lang=xx becomes public.
After the client is forcefully redirected to the proper URL with a terminating /, the rewrite rules doing the internal redirect adding the lang GET parameter are executed as normal.
Here's the entire .htaccess:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.+[^/])$ $1/ [R,L]
RewriteCond %{HTTP_HOST} ^(.*)\.example\.com$ [NC]
RewriteRule ^(.*)$ $1?lang=%1 [NC,L]
There is however another way to achieve this without using Apache config and internal redirect, and that is to examine $_SERVER['SERVER_NAME']:
<?php
list( $lang ) = explode('.', $_REQUEST['SERVER_NAME'] );

Codeigniter redirect solution

Trying to get
www.example.com/home
to go directly to
www.example.com/
What I've tried:
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com$
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^(.+)\www.example\.com$
RewriteRule ^/(.*)$ /samle/%1/$1 [L]
What am I doing wrong?
but its website rotating always .
Redirect 301 /home http://www.example.com/
If what you are saying is that you want the index function in your "home" controller to be the default homepage, you can set that in routes.php under the route['default_controller'] parameter. That way you don't need to worry about the redirect at all. If you want to remove /home anytime it's typed in, you can use a mod-rewrite like you do to remove index.php from the uri. Check out the docs for more info http://ellislab.com/codeigniter/user-guide/general/urls.html

Escaped Fragment Redirect htaccess

my website (thedutchtilt.com) employs AJAX.
Now I know that whenever Google tries to crawl a page, e.g. #!stories/component_74511, it will turn that url into thedutchtilt.com/?_escaped_fragment_=stories/component_74511 .
My question is, how do I format a htaccess redirect so that the aforementioned site will map to the other one?
I've tried
RewriteCond %{QUERY_STRING} ^_escaped_fragment_=stories/component_74511
RewriteRule ^$ http://www.thedutchtilt.com/full.html? [R=302,L]
but trying this just gives http://thedutchtilt.com/?_escaped_fragment_=stories/component_74511, which is my homepage.
I'm really confused now, and nothing seems to be working (sigh).
Kartik
Current .htaccess:
RewriteEngine on
RewriteOptions inherit
# Use PHP5 Single php.ini as default
AddHandler application/x-httpd-php5s .php
RedirectMatch ^/$ /index.html
RewriteCond %{QUERY_STRING} ^_escaped_fragment_=stories/component_74511
RewriteRule ^$ thedutchtilt.com/full.html? [R=302,L]
Thanks for providing .htaccess code. Problem is your this RedirectMatch line:
RedirectMatch ^/$ /index.html
Comment it out and try again. index.html should be loaded as default using this DirectoryIndex directive:
DirectoryIndex index.html

Mod rewrite apache - rewriting only base url

I'd like to rewrite
www.site.com/a/b/?param1=one&param2=two
in
www.site.com/c/d/e/?param1=one&param2=two.
Where www.site.com/a/b does not exists. I tried with
RewriteEngine on
Options +FollowSymLinks
RewriteRule ^a/b/(.*)$ www.site.com/c/d/e/$1 [QSA,L]
What's wrong with it?
Try this one:
RewriteEngine on
Options +FollowSymLinks
RewriteRule ^/a/b/(.*)$ /c/d/e/$1 [QSA,L]
There is no need for adding the incompleate domain. If you want that the users visit a second domain you have to add the R option and the protocol. For a redirect to a second domain try this:
RewriteRule ^/a/b/(.*)$ http://www.site.com/c/d/e/$1 [R,QSA,L]

Resources