I need to redirect an url from
http://mydomain.com/download/filename.zip
to
https://dl.dropbox.com/u/0000/filename.zip
How can I do this using mod_rewrite?
Make a .htaccess file in root of your first domain, with this rule:
RewriteEngine On
RewriteRule download/(.+) https://dl.dropbox.com/u/0000/$1 [L,R=301]
# Check to see if mod_rewrite is installed / avaliable
<IfModule mod_rewrite.c>
RewriteEngine on
# Check to see if file or directory exists
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Rewrite to Dropbox URL. Make sure you change the data after "/u/" (9502594) to your own user ID
RewriteRule ^e/(.*)$ http://dl.dropbox.com/u/9502594/$1 [L,QSA] # Embedded File
RewriteRule ^(.*)$ http://dl.dropbox.com/u/9502594/$1?dl=1 [L,QSA] # Force Download (Default)
</IfModule>
Related
I want to edit my .htaccess file so all the requests will be encrypted (I have SSL certificate active). I'm trying to run a Laravel app, which has Index file in public folder and I want to let user access my page without the /public/ part in URL.
So far, I managed to do this:
This part let me access the page without the /public/ part.
RewriteCond %{HTTP_HOST} ^domain.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^domain.com$
RewriteCond %{REQUEST_URI} !public/
RewriteRule (.*) /public/$1 [L]
This part redirects all data to HTTPS:
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://domain.club/public_html/1 [R,L]
The question is, how do I merge these two together? They work separately, but not if I put this together in .htaccess file.
.htaccess file is located in public_html which is located in root folder. Laravel folders (incluing public) are located in this folder.
Try this
.htaccess
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
I am using CMSMADESIMPLE for a website. It can generate search engine friendly URLs using a .htaccess file and mod_rewrite.
BUT it is possible to insert anything between the base url and the requested page. For example all these URLs will work:
www.example.com/aboutus
www.example.com/home/aboutus
www.example.com/any/rubbish/i/enter/aboutus
I have seen other sites using Wordpress where it is possible to enter the same in the address window, but it will redirect back to the lowest level i.e. www.example.com/aboutus. I would like to achieve the same thing but cannot master .htaccess to do it.
The relevant bits of the .htaccess file are:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?page=$1 [QSA]
</IfModule>
I am assuming that this is something that can be achieved just using mod_rewrite and doesn't require changes to the PHP code within the CMS.
If that's not possible I would like to setup a permanent redirect from some URLs within the CMS which have been indexed by Google.
i.e From www.example.com/home/aboutus to www.example.com/aboutus
I tried adding a RewriteRule to .htaccess without success:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteRule home/aboutus aboutus [R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?page=$1 [QSA]
</IfModule>
Any help appreciated.
Look at the sample htaccess.txt file in the doc folder. There is a section about parent child.
# Rewrites urls in the form of /parent/child/
# but only rewrites if the requested URL is not a file or directory
#
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?page=$1 [QSA]
i have problem about .htaccess file for my codeigniter installation.
On localhost this work fine, when i upload online its rewrite URL but the website not work.
this is my htaccess on localhost:
RewriteEngine On
RewriteBase /jCore_01/
#RewriteBase /
### Canonicalize codeigniter URLs
# If your default controller is something other than
# "welcome" you should probably change this
RewriteRule ^(welcome(/index)?|index(\.php)?)/?$ / [L,R=301]
RewriteRule ^(.*)/index/?$ $1 [L,R=301]
# Removes trailing slashes (prevents SEO duplicate content issues)
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ $1 [L,R=301]
# Enforce NO www
#RewriteCond %{HTTP_HOST} ^www [NC]
#RewriteRule ^(.*)$ http://domain.tld/$1 [L,R=301]
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
online i have a problem:
i put this file on subdomain jcore.miodomio.com and it rewrite URL but not work
example:
without htaccess it's work:
jcore.miodominio.com/index.php/en/home
with htaccess
jcore.miodominio.com/en/home
Not Found
The requested URL /en/home was not found on this server.
can anyone help me? suggestion?
regards
Denny
Try change your htaccess to:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]
Somethings to consider.
Did you enable Apache rewrite module?
If enabled check whether your virtual host file is configured properly So to make sure its hitting .htaccess or try putting some dump on .htacess , So if its hitting .htaccess than you should get an 500 server error.
If you are not getting error than its mostly the problem in your host settings.
I'm attempting to avoid urls like this one:
images/
or
images/valid-filename.png
or
images/invalid-filename.png
from being rewritten
and I've checked other example questions like .htaccess mod_rewrite on root directory but need it to skip all other directories and .htaccess mod_rewrite exemptions and this one https://stackoverflow.com/questions/7209746/can-mod-rewrite-skip-a-folder but I've not managed to get the rules to achieve what I'm after.
Here is what I have right now:
# Enable URL Rewriting
Options -Indexes
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^(scripts|styles|images)(/.*|$) - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/robots.txt
RewriteCond %{REQUEST_URI} !=/favicon.ico
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# This solved the problem
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
RewriteCond %{REQUEST_URI} !images/.* [NC]
RewriteRule ^(.*)$ index.php [L,QSA]
</IfModule>
If I navigate to www.site.com/images/, I get redirected to www.site.com
If I navigate to www.site.com/images/invalid-filename.png, I get redirected to www.site.com
but www.site.com/images/valid-filename.png loads correctly.
Could someone help to explain how to achieve the rewrite behaviour described above?
Many thanks
Try adding this RewriteCond: RewriteCond %{REQUEST_URI} !images/.* [NC]
It will check whether the URI begins with images/ and if it does, the rule will not be met.
I downloaded MyClientBase application which is based on code igniter. After the installation, I looked at the MyClientBase's website but the index.php is still there by default.
I tried to remove the index.php using the tips in codeigniter's user guide but it doesn't work.
Is there any solution out there for this issue? Thank you
I use the following .htaccess file to remove index.php. I'm not sure which one the user guide specifies, but I found this to be working perfectly:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ index.php/$1 [L]
#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#This last condition enables access to the images and css folders, and the robots.txt file
RewriteCond $1 !^(index\.php|(.*)\.swf|images|robots\.txt|css|docs|cache)
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
ErrorDocument 404 /index.php
</IfModule>
Also remove 'index.php' from your config.php file. Good luck!
i don't know if it will help but, i use this to remove my index.php from codeigniter url, create a file named .htaccess and put it to your codeigniter folder.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?/$1 [L]