0

This at first might look like a duplicate question but I have done 10 hours of research on Internet and tried almost everything I've found but no luck with mod rewrite. Most of the post/tutorials on internet are old and they haven't updated their article since then.

I can see with phpinfo(), that I have successfully loaded the mod_rewrite module.

Next I know that I have to change AllowOverride None to AllowOverride All and few more changes on Apache's default.conf file. Since I don't have a default.conf file I did those changes on000-default.conf, but mod_rewrite doesn't work. I also changed the apache.conf file, it still didn't work. I changed all files where I can see <Directory> </Directory> but it didn't work.

My root directory is not /var/www, in fact it is /var/www/html.

Here is my 000-default.conf file:

<VirtualHost *:80>
    # The ServerName directive sets the request scheme, hostname and port that
    # the server uses to identify itself. This is used when creating
    # redirection URLs. In the context of virtual hosts, the ServerName
    # specifies what hostname must appear in the request's Host: header to
    # match this virtual host. For the default virtual host (this file) this
    # value is not decisive as it is used as a last resort host regardless.
    # However, you must set it for any further virtual host explicitly.
    #ServerName www.example.com

ServerAdmin webmaster@localhost
DocumentRoot /var/www/html

# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn

ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf

 <Directory />
        Options FollowSymLinks
        AllowOverride All
 </Directory>

 <Directory /var/www>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order Allow,Deny
        Allow from All
 </Directory>

 <Directory /var/www/html>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Order Allow,Deny
    Allow from All
 </Directory>   
</VirtualHost>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

How can I get mod_rewrite to work?

10
  • 1
    "Don't work" how? Throw an error? Doesn't do what you expect to do? What you expect it to do?
    – Braiam
    Sep 13, 2014 at 18:18
  • @Braiam, I expect my CakePHP (a PHP framework) to setup properly without this frustrating error. "URL rewriting is not properly configured on your server"
    – Darin Park
    Sep 13, 2014 at 19:11
  • Is it just me or is no mention of rewriting made in that file?
    – muru
    Sep 13, 2014 at 19:11
  • @muru which file you are talking about? be more clear. we can't chat in comments. so you gotta be more specific to decrease the number of comments.
    – Darin Park
    Sep 13, 2014 at 19:13
  • 1
    Also note that if this is Apache 2.4, then instead if Allow from, I think you have to use Require all granted, etc. serverfault.com/a/549559
    – muru
    Sep 13, 2014 at 19:59

1 Answer 1

2

Problem Solved.It's a problem with CakePHP. .htaccess file of root directory was not getting copied alongside the cakePHP source.

Create a .htaccess file in your CakePHP root directory with this content

<IfModule mod_rewrite.c>
   RewriteEngine on
   RewriteRule    ^$ app/webroot/    [L]
   RewriteRule    (.*) app/webroot/$1 [L]
</IfModule>

Reference: https://stackoverflow.com/questions/10835344/cakephp-doesnt-work-url-rewriting-on-ubuntu

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .