How can I remove "index.php" from my links? - apache

Normally I access a page like this: http://localhost/codeigniter/index.php/auth/login
However I want to be able to access to the page like this : http://localhost/codeigniter/auth/login
I have no information about http.conf and .htaccess configurations.
I have set $config['index_page'] = ''; in codeigniter/application/config/config.php
my http.conf file is at its default except uncommentnig "LoadModule rewrite_module modules/mod_rewrite.so"
I inspected many proposed .htaccess files but I could not understand the logic behind the rewriting rules.
Here is the most successful .htaccess content for me. It is located at /www/CodeIgniter/ .
(by the most successful I mean that this is the only one that gives 404 error created by the CodeIgniter not by the server.)
RewriteOptions Inherit
Options -Indexes
Options +FollowSymLinks
RewriteBase /CodeIgniter/
# 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 !^(images|assets|uploads|captcha)
# do not rewrite for php files in the document root, robots.txt or the maintenance page
RewriteCond $1 !^([^\..]+\.php|robots\.txt)
# 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>
I hate requesting direct solutions however unfortunately, it is my last resort :/
Can you give me a right solution to my problem?

It's my repeat answer:
Codeigniter issues with paths in localhost (XAMPP)
please create .htaccess file in project folder and write:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Rewrite all other URLs to index.php/URL
RewriteRule ^(.*)$ index.php?url=$1 [PT,L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 index.php
</IfModule>
You don't need to define in base_url in config file:
$config['base_url'] = ''; // blank it.

put this on your htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
</IfModule>
make sure the rewrite module is enabled on your server

This is the simplest one i found which works for me :-
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]

Related

Make php files under a certain directory unaccessible using htaccess

I have a .htaccess file in place to redirect all requests that does not hit an existing file or directory to be parsed by my index.php file like this:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
# Our app bootstrap file is index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
This is working fine, But I'd like also to add another rule to prevent any direct access to php files under a certain directory, routing those calls to the same index.php file.
Like so:
request for example.com/something.php -> ok
request for example.com/themes/(anythinggoeshere)/somefile.php -> not
ok, route trough index.php
request for example.com/themes/(anythinggoeshere)/banner.png -> ok
I'm looking for a way to make those "rules" work to everything under the "themes" folder without breaking my current ones.
Thanks!
You can have a new rule to handle those .php requests:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
# handle .php requests via index.php
RewriteCond %{REQUEST_URI} !^/themes/ [NC]
RewriteRule ^[^/]+/.+?\.php$ index.php?/$1 [L,NC]
# Our app bootstrap file is index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

CodeIgniter Remove index.php with .htaccess

I've been working on this for an hour already so I figured I might as well ask.
I am trying to remove the index.php from my CodeIgniter app's URL and can not do it.
The app is running on a dedicated server in my office and I access the app through the url http://smr_local
This is my base virtual host block
<VirtualHost 192.168.1.90:80>
ServerAdmin admin#server.com
DocumentRoot "/var/www/smr.dev/app"
ServerName smr_local
ErrorLog "/etc/httpd/logs/error_log"
CustomLog "/etc/httpd/logs/access_log" common
<Directory /var/www/smr.dev/app>
Order allow,deny
Allow from all
AllowOverride All
</Directory>
<IfModule mod_rewrite.c>
RewriteEngine on
</IfModule>
</VirtualHost>
Here is my .htaccess file
RewriteEngine on
RewriteBase /
# Hide the application and system directories by redirecting the request to index.php
RewriteRule ^(application|system|\.svn) index.php/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [QSA,L]
And my config file
$config['base_url'] = "http://smr_local/";
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
Right now when I'm trying to access my base url http://smr_local/user/courses I get an error in my apache error log I get this.
File does not exist: /var/www/smr.dev/app/user
I really don't know what to try next. Any help would be appreciated.
Have you checked official user guide?
example.com/index.php/news/article/my_article
You can easily remove this file by using a .htaccess file with some simple rules. Here is an example of such a file, using the "negative" method in which everything is redirected except the specified items:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
In the above example, any HTTP request other than those for index.php, images, and robots.txt is treated as a request for your index.php file.
I have been working with Codeigniter previously and that is how I get it to work:
Here is my .htaccess (assuming you have default folder structure):
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# Removes access to the system folder by users.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
# Prevents user access to the application folder
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>
ErrorDocument 404 /index.php
</IfModule>
That is relevant part of config.php:
$config['base_url'] = '';
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';
$config['url_suffix'] = '';
If this won't help, your problem likely in Apache configuration.
Then provide your httpd.conf and any other relevant configurations, not only virtual-hosts.

Apache: Can't reroute URL from "file.123.ext" to "file.ext" using mod_rewrite in htaccess file

I'm trying to implement cache busting, as prescribed by: http://html5boilerplate.com/docs/cachebusting/
However when I add the following to the .htaccess file in my media folder:
<IfModule mod_rewrite.c>
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)\.(\d+)\.(js|css|png|jpg|gif)$ $1.$3 [L]
</IfModule>
and then I try to access a style sheet at: "/media/css/styles.1234.css", Apache complains with:
Not Found
The requested URL /media/css/styles.1234.css was not found on this server.
I can access styles.css at "/media/css/styles.css" so it's there and it works. I also know that the htaccess file gets processed because we also disallow directories from being browsed in the media folder with "Options -Indexes". Here is the htaccess file in its entirety:
Options -Indexes
AllowOverride All
<IfModule mod_rewrite.c>
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)\.(\d+)\.(js|css|png|jpg|gif)$ $1.$3 [L]
</IfModule>
Also mod_rewrite has been confirmed to be loaded with this command: 'a2enmod rewrite'. Not sure what I'm doing wrong...
Here is the solution to my problem... Even though mod_rewrite was loaded, it needed to be set to on. So I just aded "RewriteEngine On"... resulting htaccess file:
Options -Indexes
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)\.(\d+)\.(js|css|png|jpg|gif)$ $1.$3 [L]
</IfModule>
Relative path rewrite, missing RewriteBase: fail!
I had the same error, improperly used Header set X-Frame-Options "DENY". Quick fix might be to temporarily comment this out. Hope that help someone who need effective solution 'for now'.

.htaccess Wordpress Symfony

I have a Symfony 1.4 project. With standard .htaccess:
Options +FollowSymLinks +ExecCGI
<IfModule mod_rewrite.c>
RewriteEngine On
# uncomment the following line, if you are having trouble
# getting no_script_name to work
#RewriteBase /
# we skip all files with .something
#RewriteCond %{REQUEST_URI} \..+$
#RewriteCond %{REQUEST_URI} !\.html$
#RewriteRule .* - [L]
# we check if the .html version is here (caching)
RewriteRule ^$ index.html [QSA]
RewriteRule ^([^.]+)$ $1.html [QSA]
RewriteCond %{REQUEST_FILENAME} !-f
# no, so we redirect to our front web controller
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
I just want to have in my web symfony folder a Wordpress setup (in fact many, with different languages):
-web (folder)
index.php
frontend.php
-blogwordpress
-fr
index.php
-en
index.php
My question is: what should I write on .htaccess file shown before to allow a request like:
http://127.0.0.1/blogwordpress/fr
to be catched up by the Wordpress index.php, and not by the Symfony frontend ?
Of course when I type this url 404 appears on my Symfony:
404 | Not Found | sfError404Exception
Action "blogwordpress/fr" does not exist.
Thanks in advance
Add this right after the RewriteEngine On statement;
RewriteCond %{REQUEST_URI} !^/?wordpress
In layman's terms;
only apply the following rules if the request does not begin with wordpress

newbie trying to write url rewrite in .htaccess file

My site was under example.com/waha/.
Now I move the site right under the root example.com.
I want to 301 redirect all the old links like example.com/waha/notice/5803 to example.com/notice/5803.
How can I do it?
My current .htaccess file is below.
<IfModule mod_rewrite.c>
RewriteEngine On
# NOTE: change this to your actual StatusNet path; may be "/".
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) index.php?p=$1 [QSA,L]
</IfModule>
<FilesMatch "\.(ini)">
Order allow,deny
</FilesMatch>
Options -Indexes
Try this rule in front of your other mod_rewrite rule:
RewriteRule ^waha/(.*) /$1 [L,R=301]