Enable Mod_rewrite

The Apache mod_rewrite module makes it easy for you to use Google friendly URLs for your dynamic web pages which are human readable and meaningful rather than an obscure string of mumbo jumbo.

For example: this web page has the path /topic/enable-mod_rewrite rather than its machine URL which is /node/519. Check it out and see! Though this rewrite isn't using the apache module, the concept is the same.

To enable Mod_wewrite on Ubuntu is simple enough.

Enable mod_rewrite

sudo a2enmod rewrite

With your favourite editor edit the line in your apache config that says

AllowOverride none

to

AllowOverride all

I use vim but you can easily use gedit or nano.

To edit my default http config file I ran this in my command line and made the edit above.

sudo vim /etc/apache2/sites-available/default

Now you need to Restart Apache:

sudo /etc/init.d/apache2 restart

Now you're done!

To check your mod_rewrite is enabled


sudo apache2ctl -M

This should output your enabled modules.

Next you'll need to learn how to rewrite your URLs so they're pretty URLs. There's a good tutorial here on sitepoint.




Drupal mod_rewrite doesn't work

If you're stuck because Drupal's clean urls isn't working you can disable it after you log in by appending this query to the root URL:

/?q=admin/settings/clean-urls

That will get you to the form that disables it.

Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options