I have been looking all over and I can't find a solution that works for me.
I'm trying to redirect http://example.com/files/file.ext -> http://example.com/users/documents/file.ext
No matter what I try when I got directly to the file it downloads it. The GET request for the file doesn't show in any of my apache logs either. I have logging on debug.
[Edit]
The files I'm trying to download are of various types including ppt, pdf, xls, zip, doc, etc. I want to rewrite the filename to the end of the new URI. I am also using CodeIgniter so /users/documents/ is a RESTy uri.
Anyone have a fix?
Here is my .htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine On
Options +FollowSymLinks
RewriteBase /
#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#When your application folder isn't in the system folder
#This snippet prevents user access to the application folder
#Submitted by: Fabdrol
#Rename 'application' to your applications folder name.
RewriteCond %{REQUEST_URI} ^application.*
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
<IfModule mod_php5.c>
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [N]
RewriteCond %{REQUEST_URI} ^/files/ [NC]
RewriteRule ^/files/(.*)$ /users/documents/$1 [L,R=301]
</IfModule>
<IfModule !mod_php5.c>
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
</IfModule>
If this is in your htaccess file, try replacing this line:
RewriteRule ^/files/(.*)$ /users/documents/$1 [L,R=301]
with:
RewriteRule ^/?files/(.*)$ /users/documents/$1 [L,R=301]
And putting the condition and rule before any of the index.php routing rules.
I went to http://martinmelin.se/rewrite-rule-tester/ and tested my rewrite rules.
It said the RewriteCond wasn't matching anything, but when I remove the rule it matches.
Working Rule:
RewriteRule ^/?files/(.*)$ /users/documents/$1 [L,R=301]
Moving this to the top of the htaccess file fixes the issue.
Related
I had a codeigniter proyect working in windows with XAMPP and now I was moving it to my RaspberryPi:
Apache/2.2.22 (Debian)
PHP 5.4.4-14+deb7u5
mysql Ver 14.14 Distrib 5.5.31
I have two codeignitir aplications (principal and panel) with this estructure
/ -> (apache root folder)
/appname/admin
/admin/application/ -> (codeigniter application to panel)
/appname/application/ -> (codeigniter application to public)
Now I can't access to admin controllers and I think is because .htaccess. I get this in some url:
my.domain/appname -> codeigniter welcome for public (this part is empty so I think is OK)
my.domain/appname/admin/login.html -> Not Found. The requested URL /mydomain/admin/login was not found on this server.
my.domain/appname/admin/index.php?controller=admin -> 404 Page Not Found (codeigniter style)
my.domain/appname/admin/hello.html -> hello (a dummy file I put to try, works ok)
In my codeigniter panel proyect I have
$config['base_url'] = 'http://my.domain/myapp/admin/';
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';
$config['url_suffix'] = '.html';
I think it's all about .htaccess but I don't understand them. How many files I need? What folders?
I had this .htaccess in my /appname & /appname/panel before
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /appname #to panel /appname/panel
#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#‘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|images|robots\.txt|css)
RewriteRule .* index.php/$0 [PT,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>
I think RewriteEngine on is activated in my apache2.
I found solution by .htaccess inside admin's folder:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /appname/admin
#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#When your application folder isn't in the system folder
#This snippet prevents user access to the application folder
#Submitted by: Fabdrol
#Rename 'appname' to your applications folder name.
RewriteCond %{REQUEST_URI} ^appname.*
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
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.
# Submitted by: ElliotHaughin
ErrorDocument 404 /index.php
</IfModule>
CodeIgniter multiple applications htaccess
<IfModule authz_core_module>
RewriteEngine on
RewriteRule ^([a-z0-9_-]+)\.html$ index.php/page/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|asset|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
I have a url: http://localhost/mypay/admin/company/edit/profile
Is it possible to make it more like a native fashion way:
http://localhost/mypay/admin/company/?edit=profile
I currently have a .htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /mypay/
#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#When your application folder isn't in the system folder
#This snippet prevents user access to the application folder
#Submitted by: Fabdrol
#Rename 'application' to your applications folder name.
RewriteCond %{REQUEST_URI} ^application.*
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
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.
# Submitted by: ElliotHaughin
ErrorDocument 404 /index.php
</IfModule>
I've seen it to other sites and wanted it to be used in mine for easy readability. Thank you.
james
If you want to enable the $_GET array, in config/config.php set these values:
$config['allow_get_array'] = TRUE;
$config['enable_query_strings'] = TRUE;
In your controller you can then do:
$edit = $this->input->get('edit');
I've been working on a codeigniter application. When I first started developing it I used the following url structure:
http://somewebsite.com/application/login/
I changed the site to run over https
https://www.somewebsite.com/application/login/
The problem is any calls to the server only work like this.
https://www.somewebsite.com/application/index.php/login/
I want to get rid of the index.php. Any thoughts?
You need to have you .htaccess rewrite SSL properly. This is an .htaccess I use that works - although it FORCES SSL. Not sure if you want to do that:
<IfModule mod_rewrite.c>
RewriteEngine On
#Force SSL
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://yourdomain.com/$1 [R,L]
#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#When your application folder isn't in the system folder
#This snippet prevents user access to the application folder
#Submitted by: Fabdrol
#Rename 'application' to your applications folder name.
RewriteCond %{REQUEST_URI} ^application.*
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
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.
# Submitted by: ElliotHaughin
ErrorDocument 404 /index.php
</IfModule>
check and edit the application/config/config.php.
in that change the following line
$config['index_page'] = 'index.php';
to
$config['index_page'] = '';
just remove index.php and then it should work lust fine...
I have a domain example.com and mainexample.com- i want a example.com to point to mainexample.com/social/pre/register/121 which already driven by the htaccess file.
I am not sure how to go about this.. I have pointed the two domains at the same directory. I'm on a virtual shared server so I am using directadmin with php/codeigniter.
The site uses the standard htaccess file for codeigniter listed below
RewriteEngine On
RewriteBase /upd8r_jul
#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#When your application folder isn't in the system folder
#This snippet prevents user access to the application folder
#Submitted by: Fabdrol
#Rename 'application' to your applications folder name.
RewriteCond %{REQUEST_URI} ^application.*
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
RewriteRule ^(.*)$ index.php?/$1 [L]
You're going to want to add slashes to the %{REQUEST_URI} lines, because they all look like /something and not something like the URI's used against matches in RewriteRule's. But that does affect the question you're asking.
If you want to redirect http://example.com/ to http://mainexample.com/social/pre/register/121 then add these rules above the rules you already have in your htaccess file:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC]
RewriteRule ^$ http://mainexample.com/social/pre/register/121 [L,R=301]
Wonder if anyone can help with this .htaccess problem - I've had it working for months and now it's stopped working after some stupid delete errors on my part, but now have no idea how to sort this problem.
If anyone could help it'd be much appreciated!
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /MMSFL/
#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#When your application folder isn't in the system folder
#This snippet prevents user access to the application folder
#Submitted by: Fabdrol
#Rename 'application' to your applications folder name.
RewriteCond %{REQUEST_URI} ^application.*
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
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.
# Submitted by: ElliotHaughin
ErrorDocument 404 /index.php
</IfModule>
A couple of changes made here try it out and see if this works:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /MMSFL/
#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php/$1 [L]
#When your application folder isn't in the system folder
#This snippet prevents user access to the application folder
#Submitted by: Fabdrol
#Rename 'application' to your applications folder name.
RewriteCond %{REQUEST_URI} ^application.*
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
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
</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.
# Submitted by: ElliotHaughin
ErrorDocument 404 /index.php
</IfModule>
Also make sure your directory is correct. (In RewriteBase)