Install and configure mod_rewrite for Apache 2 on

2019-01-31 12:33发布

I getting started with zend framework 2 and they have a prerequisite of an installation and configuration of mod_rewrite for apache. Apache 2.2.22 came pre-installed on Mac OS X 10.8.2. Is there an easy way to install and configure mod_rewrite for apache?

The only help I have come across suggests to recompile apache. Is this the only way?

8条回答
仙女界的扛把子
2楼-- · 2019-01-31 12:36

If you are serving your site from ~/Sites, the trick for me was modifying my /private/etc/apache2/users/USERNAME.conf file. Initially, the content was:

<Directory "/Users/USERNAME/Sites/">
    Options Indexes MultiViews FollowSymLinks ExecCGI
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>

Changing AllowOverride to all and then restarting the server with a quick sudo apachectl restart enabled me to start using mod_rewrite in .htaccess files living beneath ~/Sites.

查看更多
乱世女痞
3楼-- · 2019-01-31 12:40

Rob Allen's answer sounds right, but I've never used the default installation of Apache on my Mac so I can't verify. I would recommend either MAMP or Zend Server CE.

It took me a little while to get Zend Server CE configured and running correctly on my Mac, but that was version 4 and it was buggy and either way it was well worth it. Conversely, version 5.6 of ZSCE seems to be much better!

Some notes on Zend Server CE for Mac OS X

If you go with MAMP, it should be a very quick install, aside from configuring virtual hosts.

Note that both of these come with mod_rewrite already installed.

查看更多
冷血范
4楼-- · 2019-01-31 12:44

yosemite os x should be like this:

<VirtualHost *:80>
    ServerAdmin enzo@enzolutions.com
    DocumentRoot "/Users/enzo/www/drupal8"

    ServerName drupal8

    #ServerAlias www.dummy-host.example.com
    <Directory /Users/enzo/www/drupal8>
        Require all granted
        Options Includes FollowSymLinks
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>

    ErrorLog "/private/var/log/apache2/drupal8-error.log"
    CustomLog "/private/var/log/apache2/drupal8-access.log" common
</VirtualHost>

gotten from this blog post

查看更多
我想做一个坏孩纸
5楼-- · 2019-01-31 12:45

In addition to Rob Allen's response, both line numbers are located around 168 and 169 (to save you some time from scrolling the 500+ lines of text). Also, to explain what each line does exactly:

LoadModule rewrite_module libexec/apache2/mod_rewrite.so

This overrides the default settings for any .htaccess files used at the document root

LoadModule php5_module        libexec/apache2/libphp5.so

This allows URL rewrites for permalinks

Source: link

查看更多
何必那么认真
6楼-- · 2019-01-31 12:48

Add this to http-vhosts.conf file

<Directory "/Library/WebServer/Documents">
  Options Indexes FollowSymLinks MultiViews
  AllowOverride All
  Order allow,deny
  Allow from all
</Directory>

Don't forget to reload your apache using this commande

sudo apachectl restart

Good luck

查看更多
别忘想泡老子
7楼-- · 2019-01-31 12:51

My chose

<VirtualHost *:80>
    <Directory />
            Options Indexes FollowSymLinks MultiViews
            AllowOverride All
            Order allow,deny
            Allow from all
    </Directory>
    ServerAdmin user@domain.ru
    DocumentRoot "/Users/r00we/sites/buytocoins.ru"
    ServerName site.ru
    ServerAlias www.site.ru
    ErrorLog "/private/var/log/apache2/myfaketestsite.com-error_log"
    CustomLog "/private/var/log/apache2/myfaketestsite.com-access_log" common
</VirtualHost>
查看更多
登录 后发表回答