Right now I have in .htaccess
RewriteCond %{HTTP_HOST} ^(tiny.url) [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
This works well. If I include a path with it then it translates it to the full url.
Ex:
tiny.url/somefolder
then goes to
www.example.com/somefolder
How do I do this in haproxy.
I have:
redirect location
http://www.example.com if { hdr(host) -i tiny.url }
This works but it doesn't allow a full path to be translated to the full url. How do I do that. I can't find anything in the haproxy help to help. I'm sure I just don't know what to type to find the help I need.
I have not tested this but I think you need to use redirect in prefix mode something like this:
redirect prefix http://www.example.com if { hdr(host) -i tiny.url }
Hope that helps.
Related
I want to have a redirect using mod_rewrite.
When someone opens http://aswt.mobileworldindia.com
then they will be automatically redirected to http://www.mobileworldindia.com/panels/mobile/index.php?subdomain=aswt
Please note that http://aswt.mobileworldindia.com is not an actual subdomain and doesn't exist at all and neither I want to have it. I just want to have a redirect in my site.
Tried following code but didnt work, can anybody tell me where I am wrong.
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(.+)\.sellingsellingsold\.co.uk$
RewriteRule ^$ /index.php?subdomain=%1 [L,R=301]
This is uploaded at sellingsellingsold's root and I am trying to open http://aswt.sellingsellingsold.co.uk.
Please help me in getting it sorted. It has been 2 weeks since I am trying to achieve the redirection.
Something like this inside the main server configuration or inside a .htaccess file. Using the server configuration is preferred and more reliable.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(aswt)\.mobileworldindia\.com$
RewriteRule ^$ /panels/mobile/index.php?subdomain=%1 [L,R=301]
If you want to redirect from any possible subdomain instead of just "aswt." use (.+) instead of (aswt).
I looked for the answer to this since it should be a rather common thing to do
and found some but the all lead me to an internal server error.. :(
i need to redirect all my html pages to their counter part in php
i know there is a rewriteRule i can use but cant seem to find the syntax..
a simple explenation:
i need to redirect all my *.html pages to *.php
I hope i explained it well.. would love your help or a link to some resources on this subject where i can really understand how to create this redirectRule
Create a .htaccess in the root folder of your site and place the following rules in it:
RewriteEngine on
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)\.html$ $1.php [L,R]
If you don't want the address bar to reflect the change, then change that last line to
RewriteRule ^(.*)\.html$ $1.php [QSA,L]
You can use RewriteRule:
RewriteEngine on
RewriteRule ^/(.*)\.html$ $1.php [R]
If you get Internal Server Errors, make sure that you have enabled mod_rewrite in apache :
sudo a2enmod rewrite
sudo /etc/init.d/apache2 reload
Days later I asked about redirecting dynamic directories to index.php, and I got this code that works perfect (it's the only code I have in .htaccess):
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule (.*) index.php
This translates urls like http://mydomain.example/dynamicdir/ to http://mydomain.example/index.php
Now I want to translate subdomains like http://dynamicdir.mydomain.example to http://mydomain.example/index.php?dir=dynamicdir
From examples I found in Internet I tried adding this line:
RewriteRule ^(.*)\.mydomain\.example index.php?dir=$1
But it doesn't work. I don't have enough experience with mod-rewrite to tell what's missing or wrong. Could you please help me to find a way to keep the dynamic directory translation, and add the catch-all subdomain rule?
Regards!
The mod_rewrite rules use the request path, which is relative to the virtual host. Try having different rewrite rules for each virtual host, but placing their documents in the same directory.
With RewriteRule you can only test the URL path. For the host name, you need to use %{HTTP_HOST} in a RewriteCond:
RewriteCond %{HTTP_HOST} ^(.+)\.example\.example$
RewriteRule ^ index.php?dir=%1
how can i redirect index.php?search= to the base url? I tried it with this code:
redirectMatch 301 ^/index.php?search=(.*) http://www.yoursite.com/
but then the page loops the code if i enter the site domain..
mod_alias does only work on the URL path and not the query:
mod_alias is designed to handle simple URL manipulation tasks. For more complicated tasks such as manipulating the query string, use the tools provided by mod_rewrite.
So try mod_rewrite instead:
RewriteEngine on
RewriteCond %{QUERY_STRING} ^search=(.*)
RewriteRule ^/index\.php$ /? [L,R=301]
Or more general:
RewriteEngine on
RewriteCond %{QUERY_STRING} ^([^&]*&+)*search=([^&]*)
RewriteRule ^/index\.php$ /? [L,R=301]
And if you want to use this rule the .htaccess file in your root directory, remove the leading slash from the patterns.
Try:
RedirectMatch permanent ^/index.php?search=(.*)$ http://www.yoursite.com/
I have a sub domain that I want to redirect to a different location using mod_rewrite. For example:
subdomain.example.com -> www.example.com/subdomain
I don't want to send a redirect to the browser though (so it doesn't know the page is different).
BTW subdomain.example.com has a CNAME record pointing to example.com.
Edit
Another example, just to clarify. It is very simple: If http://x.abc.com is entered in to the browser, Apache returns the contents of http://www.abc.com/x.
If both domains share the same directory, you could do this to rewrite the requests internal:
RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.com$
RewriteRule !^subdomain/ subdomain%{REQUEST_URI}
After the question has been clarified: This one works for me:
RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.com$
RewriteCond %1.%{THE_REQUEST} ^([^.]+)\.[A-Z]+\ (/[^\ ]*)
RewriteCond %{DOCUMENT_ROOT}$1 !-d
RewriteRule ^([^/]+)? %1%2
But you better go with what Brandon said.
In addition to what Gumbo stated above, you can use Apache's VirtualDocumentRoot statement to dynamically map URL to a dynamic location on disk. It allows you to use parts of the URL to build a path on disk. Check out this link for more information:
http://httpd.apache.org/docs/2.2/mod/mod_vhost_alias.html
Example:
URL = http://sub.example.com/dir/page.html
Server Path = /var/www/site.com/htdocs/sub/dir/page.html
VirtualDocumentRoot = /var/www/%-2.0.%-1.0/htdocs/%-3/
RewriteCond %{HTTP_HOST} ^([^.]+)\.abc\.com$
RewriteRule ^(.*)$ http://www.abc.com/%1$1 [R=301]