I want to Use dropbox download links with my custom domain.
example: dropbox file download URL - https://www.dropbox.com/s/ABCD/filename?dl=1
It's returning direct download that's fine. I want to do with https://mydomain/s/ABCD/filename?dl=1. Where ABCD will be dynamic.
Is This Possible?
EDIT: In case you want to hit URL http://yourdomain/s/filename/dl=1(as per samples only) and which should be served by backend url http://dropbox then try following.
RewriteEngine ON
RewriteCond %{HTTP_HOST} ^(?:www\.)mydomain(?:\.com)?$ [NC]
RewriteCond %{REQUEST_URI} ^/s/[\w-]+/?$ [NC]
RewriteCond %{QUERY_STRING} ^dl=1 [NC]
RewriteRule ^(.*)$ https://www.dropbox.com%{REQUEST_URI} [NE,QSA,L]
This assumes that we want to hit http://dropbox.com/ which should be served by http://yourdomain/ Based on your shown samples, could you please try following. Please make sure you clear your browser cache before testing these URLs.
RewriteEngine ON
RewriteCond %{HTTP_HOST} ^(?:www\.)dropbox\.com [NC]
RewriteRule ^(.*)$ https://mydomain%{REQUEST_URI} [NE,QSA,L]
Related
I am in a situation where an user can create his blog in a subdomain.
Users will create blogs and enter the address he wants like say,
abcd.domain.com Then my php code creates a directory called abcd.
To view the blog user will type in abcd.domain.com in his browser and I want a .htaccess code which will rewrite the url and open the files inside the domain.com/abcd
But for the user the url in the browser should stay abcd.domain.com
Currently I am trying this code
RewriteCond %{HTTP_HOST} ^test\.domain\.com$
RewriteCond %{REQUEST_URI} !^test/
RewriteRule ^(.*)$ /test/$1 [L,QSA]
But this gives me 404 even though I have a file test.html inside the test folder and trying to view that page.
Also in this situation I will have to manually make change to the .htaccess file for URL rewrite. What I want to know is if it is possible to have a wild card subdomain redirect to the respective directory.
You can use:
RewriteCond %{HTTP_HOST} ^test\.domain\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/test/
RewriteRule ^(.*)$ /test/$1 [L,QSA]
REQUEST_URI with leading /.
With wild card subdomain:
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^(.+)\.domain\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/%1/
RewriteRule ^(.*)$ /%1/$1 [L,QSA]
Note that it takes more than a rewrite rule to have wildcard subdomains. Just fyi.
You need to have created a wildcard DNS record for subdomains and also tell apache to use any subdomain request by having a ServerAlias of *.domain.com in the apache config.
Then try your rule this way and see if it works for you.
RewriteCond %{HTTP_HOST} ^((?!www).+)\.domain\.com$ [NC]
RewriteCond %1::%{REQUEST_URI} !^(.*?)::/\1/?
RewriteRule ^(.*)$ /%1/$1 [L,QSA]
I'm running a wordpress installation and want to move specific feeds off-site. I've already got most of the technology down, but here's the problem. I want the following URL:
http://www.csicon.net/g/feed
to redirect to
http://feed.mesr.it/g
But if the URL comes in like this:
http://www.csicon.net/g/feed?noRedirect
I don't want it to redirect but load the original. Any thoughts?
The .htaccess file on http://www.csicon.net/ would contain:
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^\/g\/feed$ http://feed.mesr.it/g [L,R=301]
Note: It has not been tested, but you get the idea.
Later Edit: Also, this can be done in PHP.
You can use this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)csicon\.net$ [NC]
RewriteCond %{QUERY_STRING} !(^|&)noRedirect [NC]
RewriteRule ^([^/]+)/feed/?$ http://feed.mesr.it/$1 [L,NC,R=302]
I have idx feeds from idxbroker.com, but the url the provide is not such a clean url.
http://myrealestatewebsite.idxbroker.com/i/xxxx-xxxxx-xxxxx-xxx
Is there a way to change the url with htacess, so
when visitor type http://www.myrealestatewebsite.com/xxxx-xxxxx-xxxxx-xxx
is shows content of http://myrealestatewebsite.idxbroker.com/i/xxxx-xxxxx-xxxxx-xxx
Do i have to change my links also? a way that will benefit SEO as all are hosted in the main website http://www.myrealestatewebsite.com
Yes, try this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteCond %{THE_REQUEST} /i/([^\s]+) [NC]
RewriteRule ^ /%1 [R=301,L]
RewriteCond %{REQUEST_URI} !/i/ [NC]
RewriteRule ^(.+)$ /i/$1 [L]
Once that is there you can change your links to without /i/ at front. However till the time you don't change first 301 rule will take care of it.
I have a website (WordPress multisite) for which I've moved a bunch of content from the route domain (http://domain[dot]com) to a sub domain (http://sub.domain[dot]com). Now I need to direct users to all the pages of the route site (http://domain[dot]com/page) to their new location (http://sub.domain[dot]com/page). But... and here's the bit I'm really struggling with... I need to omit the route url from this re-write as there is another 'geo-redirect' in place that I need to not affect. What I need to do therefore is redirect ONLY those sub page and NOT the parent/main domain.
Here's (a recent iteration) of what I'm working with:
# ignore the home page, not working :(
RewriteCond %{HTTP_HOST} !^(.*)\.routetogreatness\.com$ [NC]
# redirect all the sub pages, works
RewriteCond %{HTTP_HOST} ^routetogreatness.com [NC]
RewriteRule ^(.*)$ http://global.routetogreatness.com/$1 [L,R=301]
Any help will be very gratefully received.
I think what you are searching for is a condition that checks if the file that is requested is not a filename. That's what RewriteCond %{REQUEST_FILENAME} !-f. It is true if %{REQUEST_FILENAME} (I believe an absolute path to a file on the server, based on the request), is not a file. (Please note: I haven't tested this code as I don't have access to a server at this location, but I think it should work.)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{HTTP_HOST} ^domain.com [NC]
RewriteRule ^(.*)$ http://sub.domain.com/$1 [L,R=301]
An other solution would be to only rewrite the url if the requested url contains a slash. It would redirect domain.com/folder/index.php, but not domain.com/index.php.
RewriteCond %{REQUEST_URI} ^/([^/]+)/(.+)$
RewriteCond %{HTTP_HOST} ^domain.com [NC]
RewriteRule ^(.*)$ http://sub.domain.com/$1 [L,R=301]
Okay, so the above solution didn't quite work out for me as it turned out that while this worked beautifully on sub/child page, it would skip over parent pages as well as the home page (like domain/news for example. I've eventually run with this:
RewriteCond %{REQUEST_URI} !^/$
RewriteCond %{HTTP_HOST} ^domain.com [NC]
RewriteRule ^(.*)$ http://sub.domain.com/$1 [L,R=301]
This just skips over the home page or root URL and redirects everything else, even 404s.
I'm in the process of setting up a static cookieless domain, and everything is working great!
But im wanting to know how to redirect if the request isn't to an image/js/css file, to avoid duplicate content from the cookieless domain.
I have this:
RewriteCond %{HTTP_REFERER} ^http://files\.my-static-site\.com/ [NC]
RewriteRule \.(html|php)$ - [F,NC,L]
and it works, but it still loads the home page if you simply put files.my-static-site.com.
If you click on a link on the page your shown a 403. How do i change that to 301 redirect to the main domain instead of showing a 403?
Try changing it to this:
RewriteCond %{HTTP_HOST} ^files\.my-static-site\.com$ [NC]
RewriteRule \.(html|php)$ http://main.domain.com/ [R=301,NC,L]
RewriteCond %{HTTP_HOST} ^files\.my-static-site\.com$ [NC]
RewriteRule ^$ http://main.domain.com/ [R=301,NC,L]