I can't hide Codeigniter index.php on XAMPP 1.7.3
URL:
http://localhost/Servidor/agentesRainbow/index.php/agentes/tony
tony is an argument
My actual .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /Servidor/agentesRainbow/
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /Servidor/agentesRainbow/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|css|public|)
RewriteRule ^(.*)$ /Servidor/agentesRainbow/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 /application/errors/404.php
</IfModule>
My routes.php:
$route['agentes/(:any)'] = "agentes/index/$1";
$route['default_controller'] = "agentes";
$route['scaffolding_trigger'] = "";
My config.php:
$config['base_url'] = "http://localhost/Servidor/agentesRainbow/";
$config['index_page'] = "";
$config['uri_protocol'] = "AUTO";
On httpd.conf:
LoadModule rewrite_module modules/mod_rewrite.so
<Directory />
Options FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
</Directory>
<Directory /Servidor/agentesRainbow/>
Options FollowSymLinks
AllowOverride All
Order deny,allow
Deny from all
</Directory>
Add this line to the REQUEST_FILENAME conditions:
RewriteRule ^(.*)$ /Servidor/agentesRainbow/index.php/$1 [L]
Here is the updated .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /Servidor/agentesRainbow/
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /Servidor/agentesRainbow/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 ^(.*)$ /Servidor/agentesRainbow/index.php/$1 [L]
#This last condition enables access to the images and css folders, and the robots.txt file
RewriteCond $1 !^(index\.php|images|css|public)
RewriteRule ^(.*)$ /Servidor/agentesRainbow/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 /application/errors/404.php
</IfModule>
Hope it solves your problem!
I think the bar at the end of the rewrite condition is causing a problem. At least it broke the rewriting for me.
RewriteCond $1 !^(index\.php|images|css|public|)
Try removing the bar.
RewriteCond $1 !^(index\.php|images|css|public)
base_url should be just "http://localhost";
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond $1 !^(index\.php|other|directories|you|want|accessible|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
Related
I'm struggling with the .htaccess file. I've wordpress installed in a subdirectory 'wordpress'. In the root folder if have the htaccess with the following content:
Order Allow,Deny
Allow from all
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$
RewriteRule !^wordpress/ /wordpress%{REQUEST_URI} [L,R=301]
</IfModule>
Redirection is working, but how can I hide the subfolder 'wordpress'?
THX in advance
EDIT: Tried following content now but still not working:
root htaccess:
Order Allow,Deny
Allow from all
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com
RewriteRule !^wordpress/ wordpress%{REQUEST_URI} [L]
</IfModule>
wordpress htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /wordpress/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wordpress/index.php [L]
</IfModule>
EDIT2: my whole root htaccess looks like this now:
Allow from all
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com
RewriteRule !^wordpress/ wordpress%{REQUEST_URI} [L]
If i type in www.example.com I am redirected to example/wordpress/home, example/wordpress/contact and so on...
I would like to hide the wordpress directory like example/home, example/contact and so on
Redirection is working, but how can I hide the subfolder 'wordpress'?
You shouldn't be "redirecting". You should be internally rewriting the request instead. Remove the R flag.
For example:
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com
RewriteRule !^wordpress/ wordpress%{REQUEST_URI} [L]
The slash prefix on the susbtitution string is also not required.
This assumes you have the standard WP .htaccess file in the /wordpress subdirectory.
UPDATE: Also confirm you have removed the /wordpress subdirectory from the "Website Address" and "Site Address" in WordPress General settings.
I tried all solutions I found about removing index.php from the URL, but I still cannot make it work properly.
Problem:
the URL http://localhost/rc/index.php/person/find shows the correct page.
the URL http://localhost/rc/person/find shows the WAMP main page (without any image) like it redirects to the root's parent folder.
my configuration:
I created .htaccess is placed in my root directory (/www/rc/.htaccess) which contains the following code:
<IfModule mod_rewrite.c>
# Turn on MOD REWRITE engine
RewriteEngine On
#Remove index.php from the URL
RewriteBase /rc/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
#Also tried the following lines without success
#RewriteRule .* index.php/$0 [PT,L]
#RewriteRule ^(.*)$ index.php/$1 [L,QSA]
</IfModule>
<IfModule !mod_rewrite.c>
# If mod_rewrite is not installed, fire 404 error
ErrorDocument 404 /index.php
</IfModule>
I have also set $config['index_page'] = ''; (in www/rc/application/config/config.php file).
You must put your rule before CodeIgniter's main rule.
Replace your current code by this one (your htaccess has to be in rc folder)
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /rc/
RewriteCond %{THE_REQUEST} \s/rc/index\.php/([^\s]+) [NC]
RewriteRule . %1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>
The answer was given by Justin Iurman in the comment of the first answer:
Are you sure mod_rewrite is enabled ? You can check it in your apache config
This can be enabled in httpd.conf file or from the WAMP tray icon.
This is my first question.
I have an wp-site on the root directory and it's own .htaccess file.
RewriteEngine off
<IfModule mod_suphp.c>
suPHP_ConfigPath /home/katambi/public_html/php.ini
<Files php.ini>
order allow,deny
deny from all
</Files>
</IfModule>
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
On another directory I've SocialEngine network site. It also has .htaccess file.
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
# Get rid of index.php
RewriteCond %{REQUEST_URI} /index\.php
RewriteRule (.*) index.php?rewrite=2 [L,QSA]
# Rewrite all directory-looking urls
RewriteCond %{REQUEST_URI} /$
RewriteRule (.*) index.php?rewrite=1 [L,QSA]
# Try to route missing files
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} public\/ [OR]
RewriteCond %{REQUEST_FILENAME} \.(jpg|gif|png|ico|flv|htm|html|php|css|js)$
RewriteRule . - [L]
# If the file doesn't exist, rewrite to index
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?rewrite=1 [L,QSA]
</IfModule>
Problem: when i enter to package and plugins page it display 404 error. =(
When i delete code between
# BEGIN WordPress
and
# END WordPress
wp-site down but social network runs correct.
Thanks for your answers.
The code between # BEGIN WordPress and # END WordPress is redirecting all request to root directory's index.php. You need to make sure that requests to SocialEngine's directory is not being redirected. So you can try this solution- .htaccess & Wordpress: Exclude folder from RewriteRule
I have html static files on my server. I want the access rules as -
If user visits http://example.com/test/ he should get the contents of the file http://example.com/test.html
If the user visits http://example.com/test (without the trailing slash), he gets redirected to http://example.com/test/ (which runs rule 1 and gets him the contents of the file test.html)
Rules 1 and 2 should only fire if the file test.html exists.
So far, I have -
Options All -Indexes -Multiviews
# Do not return details of server
ServerSignature Off
<IfModule mod_rewrite.c>
DirectorySlash Off
RewriteEngine On
RewriteBase /
# If it's a request to index.html
RewriteCond %{THE_REQUEST} \ /(.+/)?index\.html(\?.*)?\ [NC]
# Remove it.
RewriteRule ^(.+/)?index\.html$ /%1 [R=301,L]
# Add missing trailing slashes to directories if a matching .html does not exist.
RewriteCond %{SCRIPT_FILENAME}/ -d
RewriteCond %{SCRIPT_FILENAME}.html !-f
RewriteRule [^/]$ %{REQUEST_URI}/ [R=301,L]
# If it's a request from a browser, not an internal request by Apache/mod_rewrite.
RewriteCond %{ENV:REDIRECT_STATUS} ^$
# And the request has a HTML extension. Redirect to remove it.
RewriteRule ^(.+)\.html$ /$1 [R=301,L]
# If the request exists with a .html extension.
RewriteCond %{SCRIPT_FILENAME}.html -f
RewriteRule ^(.*)/?$ $1.html [QSA,L]
</IfModule>
Although it works for http://example.com/test, it fails for http://example.com/test/ (500 internal error)
Shouldn't the second last line take care of trailing slashes?
[Update]
If I use Gumbo suggestions (.htaccess follows), I get a 404 for both http://example.com/test and http://example.com/test/ (with trailing slash)
Options All -Indexes -Multiviews
# Do not return details of server
ServerSignature Off
ErrorDocument 404 /404.html
# Hide .htaccess
<Files ~ "^\.ht">
Order allow,deny
Deny from all
</Files>
<IfModule mod_rewrite.c>
DirectorySlash On
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^[^/]+$ %{REQUEST_URI}/ [L,R=301]
RewriteRule ^([^/]+)/$ $1.html [L]
</IfModule>
[Update 2]
I have given up. The code below works, but instead of forcing everything end with a / (http://example.com/test/), it removes the trailing slash (http://example.com/test). On the bright side, it ensures that the content is pointed to by only one url, preserving SEO. I'm going to live with it for now.
Options All -Indexes -Multiviews
# Do not return details of server
ServerSignature Off
ErrorDocument 404 /404.html
# Hide .htaccess
<Files ~ "^\.ht">
Order allow,deny
Deny from all
</Files>
<IfModule mod_rewrite.c>
DirectorySlash On
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ /$1 [R=301,L]
# If the request exists with a .html extension.
RewriteCond %{SCRIPT_FILENAME}.html -f
# And there is no trailing slash, rewrite to add the .html extesion.
RewriteRule [^/]$ %{REQUEST_URI}.html [QSA,L]
</IfModule>
Try these rules:
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^[^/]+$ %{REQUEST_URI}/ [L,R=301]
RewriteRule ^([^/]+)/$ $1.html [L]
I have a problem with my two RewriteRules.
.htaccess:
# protect the htaccess file
<files .htaccess>
order allow,deny
deny from all
</files>
RewriteEngine On
Options +FollowSymlinks
Options -Indexes
RewriteBase /test/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^download/([0-9]+)$ download.php?id=$1 [L]
RewriteRule ^(.*)$ index.php?c=view&misc=$1 [B]
If the url contains download (some like this: mydomain.com/download/9) the first rule should redict this request to download.php?id=9. But it doesn't.
var_dump($_GET) shows the following:
array(2) { ["c"]=> string(4) "view" ["misc"]=> string(9) "index.php" } index.php
Any ideas?
Ok, I solved the problem.
# protect the htaccess file
<files .htaccess>
order allow,deny
deny from all
</files>
RewriteEngine On
Options +FollowSymlinks
Options -Indexes
RewriteBase /test/download/
RewriteRule ^download/([0-9]+)$ download.php?id=$1 [L]
RewriteBase /test/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?c=view&misc=$1 [B]
Thanks guys! :)
The problem is not with the rule. It works here.
http://wingsoflol.org/download/9
My download.php contains
Hi!
<br>Id = <?
echo $_GET['id'];
?>
and the rule is
RewriteRule ^download/([0-9]+)$ download.php?id=$1 [L]
Are you sure the RewriteBase should be /test/ ?