Im using php 5.6.40 and codeigniter 3.1.9 on Mac OS Catalina
myroutes :
$route['default_controller'] = "Homepenta";
.htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
RewriteRule ^([^\.]+)$ $1.php [NC,L]
RewriteEngine On
<Files .htaccess>
order allow,deny
deny from all
</Files>
<IfModule mod_rewrite.c>
RewriteEngine on
Options All -Indexes
</IfModule>
# php -- BEGIN cPanel-generated handler, do not edit
# This domain inherits the “PHP” package.
# php -- END cPanel-generated handler, do not edit
on browser
http:\\localhost\mastertransaksi\
show error
Directory Access is Forbidden
but if
http:\\localhost\mastertransaksi\Homepenta
its work
anyone can explation how to fix this? Thanks
It looks like your DirectoryIndex is not set, or not set correctly (it defaults to index.html only). Add the following to the top of your .htaccess file:
DirectoryIndex index.php
Your mod_rewrite directives are not rewriting /mastertransaksi/ to /mastertransaksi/index.php because this is a physical directory and your rule excludes directories.
The 403 results because directory indexes are disabled and no DirectoryIndex document is found.
Aside: You have multiple RewriteEngine directives which are unnecessary and should be removed. Also...
<IfModule mod_rewrite.c>
RewriteEngine on
Options All -Indexes
</IfModule>
Remove the <IfModule> wrapper and RewriteEngine On directive. Just keep the Options directive.
Related
I enabled mod_rewrite and checked it with phpinfo().
I placed a .htaccess file with
RewriteEngine on
RewriteRule ^(.*)$ index.php?/$1 [L]
and a index.php file at apache root directory (/var/www/html/).
Working URL:
http://192.168.56.101/index.php
http://192.168.56.101/index.php/edrgderg
Failing (404) URL:
http://192.168.56.101/sgghsshgfhfgj
Mod_rewrite should form this to http://192.168.56.101/index.php/sgghsshgfhfgj , but it doesn't.
I want to redirect each request to index.php.
SOLUTION:
I had to edit my apache configuration:
sudo nano /etc/apache2/sites-enabled/000-default.conf
I added:
<Directory /var/www/html>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
As sugested here: https://www.digitalocean.com/community/tutorials/how-to-set-up-mod_rewrite-for-apache-on-ubuntu-14-04
Exclude existing files/directories from your rewrite rule to avoid looping the rules:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* index.php?/$0 [L,QSA]
Update
I couldn't get this to work adding rules to the .htaccess file, in the end I used the Wordpress Rewrite class and added an add_rewrite_rule() to do the re-write which worked perfectly.
Original Post
I have been trying to put together a .htaccess rule to move parts of the path to a query string. As per https://wiki.apache.org/httpd/RewritePathInfo.
I have two folders in the root of my webspace, one for www.mydomain.com and one for test.mydomain.com. My .htaccess file is in the test.mydomain.com folder, and I want to rewrite test.mydomain.com/images/parm1/parm2 to test.mydomain.com/images/?gwpw=parm2&gwpi=parm1.
If I put garbage in the .htaccess file I get a 500 internal server error so I know the file is being read. I also have some existing rules in .htaccess from Wordpress that use mod_rewrite(), which if I comment out, stop the site redirecting to a 404 error page if you try to access test.mydomain.com/somegarbage. So I know mod_rewrite() is enabled.
I have read I need to set Options +FollowSymLinks -MultiViews, so the whole rule I have is:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteRule ^/images/([^/]*)/([^/]*) /images/?gwpw=$1&gwpi=$2 [PT]
I have tried this in different parts of the file, removing the leading slash from /images/?gwpw=.... I've tried adding a rule that I thought should rewrite every request to a different page like RewriteRule ^/* /somewhere but I can't seem to get any rewrite to work.
As this is a shared server I can't access httpd.conf.
My entire .htaccess file currently looks like this:
<IfModule php5_module>
php_flag session.cookie_httponly on
</IfModule>
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteRule ^/images/([^/]*)/([^/]*) /images/?gwpw=$1&gwpi=$2 [PT]
# 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
# Wordfence WAF
<Files ".user.ini">
<IfModule mod_authz_core.c>
Require all denied
</IfModule>
<IfModule !mod_authz_core.c>
Order deny,allow
Deny from all
</IfModule>
</Files>
I am a complete newbie when it comes to .htaccess rules, so any help would be greatly appreciated. I'm clearly doing something wrong but I can't see the wood for the trees anymore!
I have a laravel application having .htaccess file as below
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
RewriteRule ^ - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
I am expecting a "Authorization" key in my request headers but its not getting through in my dev server which is running Ubuntu 14.0.4.
Same OS is in my local machine and in local machine it is working perfect.
The only difference between these two environment is in my local machine i have made a VirtualHost where as i cannot make VirtualHost on dev server so i am accessing it via IP Address / projectroot
So Finally i found the reason. It was actually my Apache default configuration file was not allowing my project .htaccess file to overwrite its configurations. That is why the line in .htaccess
RewriteRule ^ - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
has no effect. To allow so I put that this directive in my apache configuration file in my case its /etc/apache2/sites-available/000-default.conf
<Directory /var/www/html/>
Options Indexes FollowSymLinks MultiViews
# AllowOverride None (Old value)
AllowOverride All #(New Value)
Order allow,deny
allow from all
# Uncomment this directive is you want to see apache2's
# default start page (in /apache2-default) when you go to /
#RedirectMatch ^/$ /apache2-default/
</Directory>
My front url is-
http://localhost/myProject/
admin url is -
http://localhost/myProject/admin
It works in windows but not works on Ubuntu.
It gives error "Not found".
What works in ubuntu -
The front page is working - http://localhost/myProject/
The admin login page is working if I add index.php in url like this -
http://localhost/myProject/index.php/admin
Not other pages are working
My .htaccess file contents-
RewriteEngine on
RewriteCond $1 !^(index\.php|assets|themes)
RewriteRule ^(.*)$ /myProject/index.php/$1 [L]
My Apache's mod-rewrite module is on.
I was also following the similar issue in Centos, and I followed the below tutorial :
How to permit changes in the .htaccess file:
open httpd using ------------------> vi /etc/httpd/conf/httpd.conf
Once inside that file, find the following section, and change the line that says AllowOverride from None to All. The section should now look like this:
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
After you save and exit that file, restart apache. .htacess files will now be available for all of your sites.
service httpd restart
Content of .htaccess file:
<IfModule mod_rewrite.c>
Options +FollowSymLinks -Indexes
RewriteEngine on
# NOTICE: If you get a 404 play with combinations of the following commented out lines
#AllowOverride All
#RewriteBase /
# Restrict your site to only one domain
#RewriteCond %{HTTP_HOST} !^www\.
#RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|images|fonts|js|images|robots\.txt|css)
<IfModule mod_php5.c>
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
<IfModule !mod_php5.c>
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
</IfModule>
#prevent access to htaccess file
<Files .htaccess>
order allow,deny
deny from all
</Files>
#disable directory browsing
Options All -Indexes
IndexIgnore *
I'm trying to create an app with laravel 4 but i'm facing a url issue. i have wamp installed on my machine. i set up a new virtual host in my httpd-vhost.conf with this code
<VirtualHost mobile.dev>
DocumentRoot "C:\wamp\www\mobile.dev\public"
ServerName mobile.dev
<Directory "C:\wamp\www\mobile.dev">
Options FollowSymLinks Indexes
AllowOverride All
Order deny,allow
Allow from 127.0.0.1
Deny from all
Require all granted
</Directory>
mobile.dev is a folder and also the domain name in my localhost.
here is my Route.php file
Route::get('/','HomeController#showWelcome');
Route::post('login','LoginController#userLogin');
Route::get('login','LoginController#getUsers');
when i ask for mobile.dev/login it gives me the requested url was not found.
can you help me please solve this issue. but when i ask for mobile.dev/ its working.
Here is my .htaccess file :
<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]
Here is more details. when i remove my htaccess content everything works fine with the default url http://mobile.dev/index.php/login
So the problem is in my htaccess and the rewriting in my virtual host
It might be not Laravel problem, but seems your wamp server haven't enabled mod_rewrite in httpd.conf file yet. Locate the line -
#LoadModule rewrite_module modules/mod_rewrite.so
and remove the comment symbol '#'. Then save the file and restart Apache.
Solution:
1- when you have wamp installed in your machine please go to C:\wamp\bin\apache\Apache*.*.*\conf\httpd.conf and make sure that rewrite_mod is enabled by deleting the hash tag. (instead of using the interface provided by wamp)
2-there are two ways to enable rewriting for laravel in .htaccess file :
<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>
or using this :
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
3- if you're setting a virtual host be sure to add this option in the <virtualhost> tag
<Directory "C:\wamp\www\mobile.dev\public">
Options FollowSymLinks Indexes Multiviews
AllowOverride All
</Directory>
Thanks a lot for your time.
Have you tried
Route::post('login','LoginController#userLogin');
without the () after userLogin?
Your <Directory "C:\wamp\www\mobile.dev"> in config should be <Directory "C:\wamp\www\mobile.dev\public"> to specify the public directory to the root of the htaccess rewrite rules.
I originally thought you were missing the </IfModule> at the end of your .htaccess file but when I posted my .htaccess file it hid the </IfModule> as well so that is a stack overflow issue. Otherwise your htaccess is correct.