How do I get mod_rewrite to work with EasyPHP? - php

My mod_rewrite fails to work. This is the mod_rewrite section:
<IfModule mod_rewrite.c>
Options +FollowSymlinks
# Options +SymLinksIfOwnerMatch
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
</IfModule>
It works like a charm on Ubuntu and OS X, but fails on EasyPHP under Windows.
I have uncommented the following line in the apache configuration:
LoadModule rewrite_module modules/mod_rewrite.so
And I have set every single AllowOverride directive to All (it's just a local server so it's irrelevant as far as security goes). The vhost entry for the particular vhost I would like mod_rewrite to be on is as follows:
<VirtualHost 127.0.0.1>
DocumentRoot "E:/Dropbox/Websites/mysite/public"
ServerName myvhost.mysite
<Directory "E:/Dropbox/Websites/mysite/public">
Options FollowSymLinks Indexes
RewriteEngine On
AllowOverride All
Order allow,deny
Allow from all
#Deny from all
Require all granted
</Directory>
</VirtualHost>
If I put a "die" at the top of the index.php file in my public folder, it never happens, so apparently the mod rewrite never even tried to redirect it to index.php. All I get are 404s.

See this answer:
easyphp and .htaccess
Default installation of Apache in EasyPHP don't have activated the option to use .htaccess files to modify server configuration in folders.
You have to tell Apache what configuration can be changed with .htaccess files, and in which folder. To enable all config changes on main web server, you should edit http.conf (in Apache/conf folder), and look for
Hope this helps :)

Related

Symfony (3.4) app : cant redirect requests to /web dir via .htaccess

I've a website lets say website.fr ( on server : /web/website ) ;
I ve added a symfony blog app in /web/website/blog/.
I dont manage to access the blog via website.fr/blog/ (404 error)
There is a .htaccess file in /web/website/blog/ directory, and one in /web/website/blog/web directory.
I am used to deploy symfony apps 'alone' on a server, and make the domain point to the web dir of the app, and everything always works fine, but in this configuration, I cant get it to work.
I have tried to use the following .htaccess conf under /web/website/blog/ :
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ web/$1 [QSA,L]
</IfModule>
And I did not edit the default one under /web/website/blog/web/
Im not sure what Im doing wrong, so any help would be appreciated !
For me I use .. nano /etc/apache2/sites-available/000-default.conf
<VirtualHost *:80>
ServerName domain.tld
ServerAlias www.domain.tld
DocumentRoot /var/www/project/web
<Directory /var/www/project/web>
AllowOverride All
Order Allow,Deny
Allow from All
</Directory>
# uncomment the following lines if you install assets as symlinks
# or run into problems when compiling LESS/Sass/CoffeeScript assets
# <Directory /var/www/project>
# Options FollowSymlinks
# </Directory>
ErrorLog /var/log/apache2/project_error.log
CustomLog /var/log/apache2/project_access.log combined
</VirtualHost>
which is explained Here and restart Apache, but I do not know if I understand your problem
I couldn't get what I wanted, but here is the solution I implemented :
I created a .htaccess in /web/website dir, that rewrites all requests to /web/website/blog, with the root (/) excluded from this rewriting :
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ blog/web/$1 [QSA,L]
</IfModule>
That's not the way I wanted to get my rewriting, but I have the result I expected ; note that it would not be a good solution for a website that would evolve with new modules, routes, folders...

wordpress redirect loop in wp-admin (apache compiled from source)

I recently set out to compile a lamp stack from source. Apache was compiled like so:
./configure --prefix=/srv/www --enable-mods-shared=most
and I can confirm mod_rewrite is enabled by placing this in the vhost for a site:
Redirect "/foo.html" "/bar.html"
However, after installing wordpress, I can log in at example.com/wp-login.php, but example.com/wp-admin loads to an error page about a redirect loop.
I'm using the default wordpress htaccess file:
# 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
and this vhost:
<VirtualHost *:80>
ServerName example.com
DocumentRoot "/srv/www/htdocs/example.com"
<Directory "/srv/www/htdocs/example.com">
options indexes followSymLinks
# AllowOverride controls what directives may be placed in .htaccess files.
AllowOverride All
# Controls who can get stuff from this server file
require all granted
rewriteEngine on
</Directory>
<IfModule mpm_peruser_module>
ServerEnvironment apache apache
</IfModule>
ErrorLog /srv/www/logs/example.com/error_log
CustomLog /srv/www/logs/example.com/access_log combined
</VirtualHost>
ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9000/srv/www/htdocs/example.com/$1
DirectoryIndex /index.php index.php
The ProxyPassMatch line is included to handle php via php-fpm.
I can include the httpd.conf if needed, but it's 506 lines long and I hear pastebin isn't received warmly here. I've checked the error log for that domain and it doesn't get updated when hitting the redirect loop, and it seems like a pretty straightforward setup with the exception of using php-fpm instead of mod_rewrite, so I'm a bit lost on where to check further.
This was compiled on centos7 so a2enmod isn't an option.
DirectoryIndex /index.php index.php
This was the issue.
DirectoryIndex index.php
This was the solution. After removing /index.php from the directoryindex directive, the site loads and the dashboard loads without issue as well.

.htaccess file not works in LAMP

This is my .htaccess file. I am used Codeigniter Framework for my project.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /project_name/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
Where is my mistake here? But It Works in xampp.
You can't just move from one server to another and not make sure your prerequistes are there. These things are not on by default on most systems. You also have not given any specifics about your setup or even your document root.
So going off that it's an Ubuntu server and apache2, you need to do these things.
First thing you need to do if this is a new LAMP install is make sure rewrite is on.
Run this command to enable mod_rewrite.
sudo a2enmod rewrite
Then you need to make sure you allow .htaccess in your document root.
edit
/etc/apache2/sites-available/000-default.conf
In this file search for this
AllowOverride None
and change it to
AllowOverride All
Then restart apache2.
sudo service apache2 restart
EDIT: Based on your comment, you need to make your vhost look like this and then restart apache2.
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory /var/www/html>
AllowOverride All
</Directory>
</VirtualHost>
Open your terminal
Run this following code:
sudo nano /etc/apache2/apache2.conf
go down and change:
AllowOverride All
look like:
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
Then restart apache2.
sudo service apache2 restart
and then .htaccess file is
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
Are you sure mod_rewrite module is loaded ? go to httpd.conf and search for -
LoadModule rewrite_module modules/mod_rewrite.so
and make sure theres no # [hash tag] before

How to access the Laravel Direct Path

Am new to laravel, I have install laravel using composer in my linux server, the problem is I couldn't able to access the domainname.com but domainname.com/public/ then only I can able to access the page. Kindly suggest me how to access the site with domainname.com/ instead of domainname.com/public/
Am running in shared hosting so there multiple domain name with folders are available as well.
First, make sure that your rewrite module is enabled. In your case, share hosting providers often enable it for you.
Second, create an .htaccess file in your home folder (the folder contains artisan file) with this content.
<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 $1 !^(public)
RewriteRule ^(.*)$ /public/$1 [L]
</IfModule>
You need to add a <VirtualHost> in your Apache configuration:
<VirtualHost *:80>
ServerAdmin admin#localhost
DocumentRoot /path/to/your/laravel/public
ServerName your.domain.com
<Directory /path/to/your/laravel/public>
AllowOverride None
Order allow,deny
Allow from All
Options FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</Directory>
</VirtualHost>
Then you can access your Laravel site as:
http://your.domain.com/

running laravel on a different port

I'm using Bitnami MampStack on OS X 10.9. Because this is an inherited laptop, I had to set up Apache under MAMP to listen on port 8888. I tweaked it to listen on 8889 as well and added the following as a VirtualHost in my httpd.conf file:
<VirtualHost *:8889>
DocumentRoot "/Applications/mampstack-5.4.26-0/apache2/htdocs/codebright/public"
ServerName localhost
<Directory "/Applications/mampstack-5.4.26-0/apache2/htdocs/codebright/public">
Require all granted
</Directory>
</VirtualHost>
I followed the example here (so all my source code matches his). The index blade works, but the edit, create, and delete blades return a 404.
As I was testing, I discovered that http://localhost:8889/create returned a 404, but http://localhost:8889/index.php/create returned the correct view. Also, browsing http://localhost:8888/codebright/public/create works as expected.
So...me being kinda new to Laravel and MVC frameworks in general, is there some way I can have this installing running properly on port 8889?
Your virtualhost is working as it should, you just have now to be sure your public/.htaccess file is in place:
<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>
This is the file that rewrites your urls removing the /index.php from them.
EDIT
Also, check if you have mod_rewrite installed and enabled, because your .htaccess uses it, in Ubuntu/Debian, to enable it, you have to execute:
sudo a2enmod rewrite
Figured it out, thanks to this. I was missing AllowOverride All in the <Directory> section. Updated httpd.conf:
<VirtualHost *:8889>
DocumentRoot "/Applications/mampstack-5.4.26-0/apache2/htdocs/codebright/public"
ServerName localhost
<Directory "/Applications/mampstack-5.4.26-0/apache2/htdocs/codebright/public">
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
I thought I might have been missing RewriteEngine On in the VirtualHost definition but it doesn't seem to have an effect on my problem.

Categories