My CodeIgniter project is placed inside sub-folders and I want to hide those two sub-folders with .htaccess.
Everything is working fine but my current URL looks like this:
example.com/folder1/folder2/ci_project/class/function/$id
I want this to be:
example.com/class/function/$id
Now, I am using this simple .htaccess code in order to remove the index.php from URL:
Options +FollowSymLinks
RewriteEngine on
# Send request via index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
Any Ideas?
when i use the following code in htaccess file inside folder1/folder2/ci_project, it does hide the sub directories but i get the error "Object not found"
RewriteCond %{REQUEST_URI} !^/folder1/folder2/ci_project/
RewriteRule ^(.*)$ /folder1/folder2/ci_project/index.php/$1 [L]
Move your current .htaccess file from your ci_project/ to the root of domain, and replace these code inside it:
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
RewriteCond $1 !^(robots\.txt|favicon\.ico|public)
RewriteRule ^(.*)$ /folder1/folder2/ci_project/index.php/$1 [L]
</IfModule>
In this case, you should place your public files in a folder like public at the root of the domain.
You should add other folders (like public) to RewriteCond if you don’t want them to be treated by RewriteRule.
If multiple application are exist in the same domain, you might want to consider this option:
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /folder1/folder2/ci_project/index.php/$1 [L]
</IfModule>
Related
When I go to http://www.example.com/youtube/detail/abvcde in my browser, I want to internally rewrite the url to http://www.example.com/youtube/detail.php?id=abvcde. I tried to do this with the following .htaccess, but it gives a 404 error.
Currently my .htaccess looks like this:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*) $1.php [L]
Put the following code in a htaccess file in server root directory:
RewriteEngine On
RewriteRule ^youtube/detail/(.+)$ youtube/detail.php?id=$1 [L]
You can put this code in your /youtube/.htaccess
Options -MultiViews
RewriteEngine On
RewriteBase /youtube/
RewriteRule ^detail/([^/]+)$ detail.php?id=$1 [L]
I'm cleaning my URLs and everything looks fine but whenever I try to access any directory such as images etc then chrome shows that "This webpage has a redirect loop." However I want to protect directories inside public_html.
The .htaccess file is inside public_html
<ifModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
RewriteRule ^(.+)/$ http://%{HTTP_HOST}/$1 [R=301,L]
</ifModule>
I want to protect images, css and javascript directories but want to allow access to the admin directory.
Thank in advance.
Change order of your rules and change your trailing slash removing rule:
<ifModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+?)/$ $1 [R=301,L]
# block all directories except admin/
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule !^admin(/|$) - [NC,F]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
</ifModule>
You can use this remove all code and use this one
option index allow and disallow to be index directory like
This does the trick.
Options All -Indexes
or
IndexIgnore *
for more information please check below link
http://viralpatel.net/blogs/htaccess-directory-listing-enable-disable-allow-deny-prevent-htaccess-directory-listing/
I want the site to be url friendly match, so that the directory / adm (which in my case is the administrative panel) has not url friendlies
my .htaccess
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
</IfModule>
# For all files not found in the file system, reroute the request to the
# "index.php" front controller, keeping the query string intact
<IfModule mod_rewrite.c>
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [L]
</IfModule>
I just want to do this I'm learning this rule means in layman commands. htaccess
All your scripts will be redirected to index.php based on below
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [L]
In addition you can specify the folder name, filename which should not follow the above rule. This can be done by adding another rewrite condition statement in your htaccess file.
RewriteCond %{REQUEST_FILENAME} !(img|anyother folders that you want to ignore|anyother folders that you want to ignore|...)
'|' is used to separate each folder name that you want to ignore
So your .htaccess file will have following
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
</IfModule>
# For all files not found in the file system, reroute the request to the
# "index.php" front controller, keeping the query string intact
<IfModule mod_rewrite.c>
RewriteCond %{REQUEST_FILENAME} !(adm|anyother folders that you want to ignore|anyother folders that you want to ignore|...)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [L]
</IfModule>
I have been trying to find a method to redirect all directories except a few to a file with a variable
Example:
site.com/test -> index.php?a=test
I want all subdirectories to be forwarded except for the following
/images
/admin
/includes
I have tried the following withough success.
RewriteCond %{REQUEST_URI} !^/images(/|$)
RewriteCond %{REQUEST_URI} !^/admin(/|$)
RewriteCond %{REQUEST_URI} !^/includes(/|$)
RewriteRule ^([\w/]*)$ index.php/?a=$1 [L]
Is there a way to complete this using .htaccess
EDIT:
I found this which is closer to what im looking for but it needs to be updated to allow access to /images /admin /includes.
Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) index.php?a=$1 [NC,L,R=301]
In .htaccess you can use this rule
RewriteEngine On
RewriteRule !\.(js|jpeg|ico|gif|jpg|png|css|xml|html|swf|zip|tar|pdf|flv|gz|wmv|avi|rar|mp3)$ index.php [L]
In your application you can get $_SERVER["REQUEST_URI"] and manipulate as you whish!
<?php
$route = explode('/', $_SERVER['REQUEST_URI']);
print_r($route);
I'm using codeigniter, and I tried to remove index.php from url by creating .htaccess file
and it contents:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
this way is working will at xampp server.
but when I uploaded the site, unfortunately there was a problem appeared:
I have a folder called files and it content sub folders: images, css, js, swf, upload.
and every file at those folders can't view, and the browser said there the file not found.
any help ploese.
Just make sure you exclude those too:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt|css|swf|upload)
RewriteRule ^(.*)$ /index.php/$1 [L]
This is my .htaccess file. My understanding is that for any file or directory which has access attempted and doesn't exist, it will forward onto Codeigniter.
Anything which does exist will work fine and will not require individual exclusion. This will save time and hassel each time you add a new directory or folder as it wont require you to edit this file.
RewriteEngine on
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
Works for us, but my understanding may well be incorrect. Hope it helps
try this one which i think will solve your problem ..
RewriteEngine on
RewriteCond $1 !^(index\.php|robots\.txt|files\/images|files\/css|files\/js|files\/swf|files\/upload)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
you have to tell your server not to handle those directories over to index.php and the line which work for this is :
RewriteCond $1 !^(index\.php|robots\.txt|files\/images|files\/css|files\/js|files\/swf|files\/upload)
Here is my .htaccess file - which should work for you:
Options -Indexes
Options +FollowSymLinks
# Set the default file for indexes
DirectoryIndex index.php
<IfModule mod_rewrite.c>
# activate URL rewriting
RewriteEngine on
# do not rewrite links to the documentation, assets and public files
RewriteCond $1 !^(files|css|js|swfimages|assets|uploads|captcha)
# do not rewrite for php files in the document root, robots.txt or the maintenance page
RewriteCond $1 !^([^\..]+\.php|robots\.txt|crossdomain\.xml|maintenance\.html)
# but rewrite everything else
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>
thank you. this worked fine:
RewriteEngine on
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
I have another website and next index.php I have a folder called files, and this one content alot of folders should I have to put all names of them and names of sub-directories in them?