Posted in

how to enable mod_rewrite in apache2.2 (debian/ubuntu)

Here i am going to describe how to enable mod_rewrite in apache2.2 -specaily for debian.

In default installion of apache2.2 on debian never enable mod_rewrite default. So you may need to enable .

First install the apache2.2 with this command :
debian user please use “su” before start this process
ubuntu user please use “sudo su” before start this process

apt-get install apache2 (it will install apache 2.2)

on current debian system you can enable mod_rewrite with simple command

a2enmod rewrite

old style, you can skip this portion

now use locate to find if the mod_rewrite.so is availble on your server

updatedb
locate mod_rewrite.so

it will found in “/usr/lib/apache2/modules”

new apache follow some folders to enable and disable mods.
so now do this:

cd /etc/apache2/mods-enabled
touch rewrite.load
gedit rewrite.load (you may use any editor to edit this file)

now paste this following line

LoadModule rewrite_module /usr/lib/apache2/modules/mod_rewrite.so

end of old style

Then edit /etc/apache2/sites-available/default or /etc/apache2/sites-available/000-default (check which one available on your system)

Find the following

Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all

and change it to

Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
allow from all

and finally restart Apache

/etc/init.d/apache2 restart
or
service apache2 restart

OK, you done 😀

don’t forget to comment, if it works or not.

thanks.

if you like my post, please tweet it, so other also can see this post.

352 thoughts on “how to enable mod_rewrite in apache2.2 (debian/ubuntu)

  1. Whoa!!

    Excellent work Lavlu, much appreciated. This was one of my major problem even few days ago. I just think why didnt you write this article that time.

    😀

    Very good work. Keep it on.

  2. Jeez.. You have no idea how glad I am i found this. I have been struggling with linux for a few days now. No idea why everything has to be this hard.

  3. Are you serious?

    Never heard about a2enmod command?

    #a2enmod rewrite
    #/etc/init.d/apache2 restart

  4. Very important to say that before you apply rewrite rules you need to say in the site configuration RewriteEngine On

    so the rewrite configuration example looks like this:

    RewriteEngine On

    # allow only for https!
    RewriteCond %{SERVER_PORT} 80
    RewriteRule ^/svn(.*) https://%{SERVER_NAME}/svn$1 [R,L]

  5. nice, it helps me a lot … but …
    when I try to change AllowOverride None to All, I get the external error and I cannot access my page…Any ideas I’d appreciate so much

  6. This could be achieved more easily by symlinking from /etc/apache2/mods-available/rewrite.load (this will also work with any of the other modules that have a file in mods-available).
    🙂

  7. this was the only tutorial that made my htaccess files work. thank you very much. good order and good explanation and descriptions.
    thanks…

  8. Most tutorials in regards of ‘mod_rewrite’ out there today, even at Apache site are often referring to older versions, so from that perspective it’s nice with a fresh tutorial.

    However if you are reading this then you should be aware of the following:

    The ‘Enabled’ directory is to contain Links into ‘Available’ directory. Doing anything else is stepping away from the intended server structure. So copy the ‘rewrite.load’ as a link from the ‘Available’ directory, into the ‘Enabled’ directory. No need to edit anything!

    The ‘000-default’ is your Apache2 server default file changes here are very global. The edit above actually opens up for the use of ex:’.htaccess’ files in the whole site.
    Normally you leave this file alone and make the appropriate changes at a lower level. Like in the ‘apache2.conf’ which is the normal place for server wide alterations.
    Just a tip…

  9. THANKS!!! I’d been racking my brains trying to get my .htaccess file working. It was full of Rewrite directives. Then I found your explanation. Worked perfectly.

    Thanks, again.

  10. whoaa…its work..thanks…but when i check the mods loaded by apache using apache2ctl -l , mod_rewrite isn’t on the list..but after all it works :p .thanks.

  11. maque, my impression is that to see the loaded modules you should do apache2ctl -M

    …and BTW Lavluda, it worked for me as well. But I’d like to know why.

    Is there a good book re Apache 2.0 somewhere? The difference between Apache 1.x and 2.x is significant re implementation. It’s much more convoluted; more confusing. So before I make my site public, I’d like to know that I haven’t compromised security in any way.

  12. This is a follow-up to my post yesterday…

    I spoke too soon. After the tweak, my other non-Drupal sites were no longer available.

    The odd thing is that after I reset everything to the initial Drupal (ie, post-install) settings, clean-urls still worked and my other non-Drupal sites were available once more.

    My system is Linux debian 2.6.26-2-amd64 (Lenny). The bottom line is, in my case, the tweak did not work.

  13. Excellent. Thank you very much, only one observation: to change the site-enable default site i recommend do this:
    (in su user)
    # a2dissite default
    # gedit /etc/apache2/sites-avaibles/default
    [Make the changes that you suggest]
    # a2ensite default
    # /etc/init.d/apache2 reload
    This because sites-enable is like a “instance” of site-avaibles in apache2.
    Regards
    Carlos

  14. You only need to link the given files from mods-available to mods-enabled
    #ln -s /etc/apache2/mods-available/rewrite.load /etc/apache2/mods-enabled/
    apache2ctl restart
    Isn’t that easier? (for debian lenny)

  15. Debian has a built in function for enabling (linking) mods and sites

    # a2enmod rewrite
    will enable mod_rewrite

    # a2ensite default
    will enable your default site

    restart or reload apache2 to see changes
    # apache2ctl restart

  16. This post help me very much. Thanks a lot.
    I use cakephp and this is an important step in the config phase to run cake successfully.

    Thanks again and best regards,
    Doan Huynh

  17. Dude, fantastic right up brother!

    I’m running turnkey LAMP vm and using webmin to enable mod_rewrite but it still wasn’t working!!! ugh…

    Followed you how to here, got in and did the dirty work the old fashioned way and BOOM! rewrites are working like a champ now!

    Thx a million!

  18. Thanks a million, this is one of those golden posts that addresses the problem perfectly – worked first time, nicely explained – fantastic!

    Was causing me a headache, was getting close to the root of the problem but you sorted it instantly – great tip. Thanks again for posting it!

  19. the google search “debian enable rewrite” lists this blog as number one, congrats. And the information works, although the information from mike [http://www.lavluda.com/2007/07/15/how-to-enable-mod_rewrite-in-apache22-debian/#comment-2598] is a cleaner way of keeping a debian config intact…

  20. Wow! [Tweeted this article!]
    I usually go with XAMPP but for a change I tried installing from synaptic and got some serious headache with httpd.conf file and to change the www directory. Even after figuring out how to enable modules myself (with links) I forgot to change the “AllowOverride all”. I was just going to remove all packages and reinstall XAMPP.
    Thank You A LOT (Jazakallahu Haira).

  21. Oh THANK YOU so much for writing this I’ve spent 4 days searching the internet for this trying everything and finally I found this and it works perfectly. I’m so relieved right now because its finally fixed 🙂

  22. Great article; however, Apache includes a function that will install the rewrite mod for you.

    sudo a2enmod rewrite

    Then finish by modifying the 000-default file as described above and restart the server.

    Cheers!

  23. I couldnt The debian gave me this error can anyone help me?

    ERROR: Module rewrite not properly enabled: /etc/apache2/mods-enabled/rewrite.load is a real file, not touching it

  24. Great job simplifying the process. I’m fairly new to *nix and following your directions was a piece of cake. I had to enable this thing to allow permalink redirect on my WordPress blog website.

  25. Solved it you superstar 🙂

    I had a live site down with no working permalinks, permalinks hardcoded into the copy all over the place and no way to fix. As you say Apache2.2 doesn’t have mod_rewrite on by default, enabling fixed all the issues. Thanks again 🙂

  26. It is great to get some advice that actually works. But this is really the wrong advice. It is correct that the rewrite module should be activated, and this solution will work. However, rewrite.load already exists in /etc/apache2/mods-available/. A link to that file should be created in /etc/apache2/mods-enabled/. It’s not that the suggestion won’t work. It is just contrary to the intended configuration of Apache2 on Debian/Ubunto (Linux ?). As a Windows developer it is a tough task switching to Linux. I hope to get advice that matches the architecture so I better understand what is going on. It was better for me to learn that available mods are specified in mods-available and are activated by linking to the proper conf file in mods-enabled rather than start generating new files in mods-enabled.

    1. @Glenn,
      you missed my point. i know it can be done with just one command “a2enmod rewrite” . but here i showed manual way, if you have a custom .so (module) to load, you must have to follow my way.

      this article is too old, will rewrite it as it’s getting huge hit every single day.

  27. Thanks, worked fine. Just the 000-default is named only “default” on my system.

  28. I just want to say I love you. I don’t care if you’re a man or a woman, but I’ve been wrestling with a WordPress install for twelve hours now, and this fixed it entirely, and I love you.

  29. I am running Ubuntu 10.04, and from the command line I tried running “a2enmod rewrite”, but that was not enough to enable the feature. However I did “sudo vi /etc/apache2/sites-available/default” (note the difference in file name), changed “Order allow,deny” to “Order allow,all”, saved my changes, and from the command line executed: “sudo service apache2 restart”.

    After apache2 came back up, the rewrite feature was enabled. THANK YOU!

    I had already installed Drupal without this feature. If anyone else is in this boat, as Drupal administrator, go to “administer >> site configuration >> clean urls”. You can run a test there to determine if the rewrite feature is enabled (in my case it seemed to auto-test it). It was. (Yay!) You can then enable Clean URLs and save your configuration changes.

  30. Hi Lavluda!

    You are the grand-ala-pubah of apache2!

    This worked perfectly for me! the “AllowOverride all” was all I was missing! Your rock!

  31. on debian5, 000-default is not loacated in sites-avaiable but in sites-enabled directory.
    so this is wrong location: /etc/apache2/sites-available/000-default
    this is correct location /etc/apache2/sites-enabled/000-default

  32. “a2enmod rewrite” returns the following:
    ERROR: Module rewrite not properly enabled: /etc/apache2/mods-enabled/rewrite.load is a real file, not touching it
    Any clues what could be wrong? 🙂

  33. Actually, all you need to do is (in Ubuntu 10.04 anyway) do:

    mv /etc/apache2/mods-available/rewrite.load /etc/apache2/mods-enabled

    /etc/apache2/mods-available contains a lot of the available mods for apagace (as the folder sname suggests. All you have to do is move it into the enabled folder then restart apache:

    service apache2 restart

    Done.

    Dan

  34. OMG, you really saved my day.
    Not before reading your post after a desperate “apache2 mod_rewrite debian” in google, did I think of verifying that my mod_rewrite was indeed working.
    Damn, 10 years doing that and still stumbling on the same old mistakes.

    Thanks a million 🙂

  35. Worked perfectly for me

    for me it was

    /etc/apache2/sites-available/default

    instead of
    Then edit /etc/apache2/sites-available/000-default

    Ibrahim, Thanks a ton.

  36. After much effort and frustration, your post helped me get to the root of my problem and solve it!
    I just want to give you a BIG thank you and appreciate your wonderful post.
    Thanks.

  37. That’s great, thank you!

    It worked perfectly in Apache 2.2.16 on Ubuntu 10.10, except that, as somebody mentioned, there was default file, not 000-default.

  38. It works man, it works!! I had used a2enmod rewrite, and that worked, but I still needed to change 000-default in Ubuntu 10.04, and my scripts worked like a charm. Thank you

  39. This worked as documented with a few minor issues:

    I am running Ubuntu 10.04.2, and like others, I found a file called /etc/apache2/sites-available/default

    instead of /etc/apache2/sites-available/000-default

    My file /etc/apache2/sites-available/default contains more than one section with:
    Options Indexes FollowSymLinks MultiViews
    AllowOverride None
    Order allow,deny
    allow from all

    The one that needed to be changed was the one prefaced by:

    Other than that, the instructions worked splendidly!
    Many thanks for making this info available. 🙂

  40. Correction to the above,

    The entry in /etc/apache2/sites-available/default that needed to be changed was the one prefaced by:
    <Directory /var/www

  41. following error was produced:

    * Restarting web server apache2 (13)Permission denied: make_sock: could not bind to address 0.0.0.0:80
    no listening sockets available, shutting down
    Unable to open logs
    [fail]

  42. Excellent post, great comments.

    I did this part differently – I edit the site Apache config file (as my sites are located in a different folder / partition to the main www folder – plus my “user” is in a SSH chroot):

    # Then edit /etc/apache2/sites-available/site-example.com

    # Find the following

    Options FollowSymLinks
    AllowOverride none
    Order allow,deny
    allow from all

    # and change it to

    Options FollowSymLinks
    AllowOverride All
    Order allow,deny
    allow from all

  43. Hello everybody!

    Greettings from Brazil!

    I was facing a nightmare to make my CodeIgniter installation remove the ‘index.php’ from the url’s on my system. Since I’m a Ubuntu newbie you guys can imagine how difficult this task could get. I had already activated the rewrite_mod but I just couldn’t find which file should I edit to make set up that “Override … ” rules. Every tutorial on internet was talking different things even when comes to Ubuntu Maverick. But thanks to our friend “G” I step up on this page and with a slitghtly different on the file name (‘000-default’ to just ‘default’ I managed to get this thing working! Thanks a lot lavluda. You just gained a (maybe another) brazilian reader!

  44. I’d suggest doing the

    updatedb

    But (especially for Ubuntu) before you try creating rewrite.load, try using:

    sudo a2enmod rewrite

    first.

    @Rohit – I’d guess the apache2ctl -l only lists the modules that are compiled in?

  45. I was able to install mod_rewrite and solve my problem using your post as a guide. Thanks!

    I did find that the second part of your instructions – the part after “Then edit /etc/apache2/sites-available/000-default” – wasn’t necessary for me to get things working.

    Perhaps my issue (WordPress permalinks formatting) is limited in scope, but I wanted others to know that you may not need to edit anything in the sites-available directory to get mod_rewrite installed and address your particular issue.

  46. Worked like a charm !
    The magic command i was missing was “a2enmod rewrite”.

    Thanks a lot.

  47. Thanks it worked perfectly.

    Google is great sometimes when it finds experts like you who give help that actually works!

    Cheers

  48. Hello – thanks so much for this post. Going mad working out why WordPress permalinks had gone wrong when I moved a site from IIS to Debian LAMP… this sorted it.

    Cheers

    Ken

  49. a2enmod rewrite command just rock !

    দুরু দুরু বুকে দিলাম কমান্ড আর কাজ হয়ে গেল 🙂

  50. thank you so much 🙂 I was googling for a few hours, trying lot of solutions only yours works, why? other bloggers ask me to change httpd.conf !

  51. i have worked several days to fix this /%¤&¤/¤##¤%¤# problem, and you solved it.

    GREAT!!

    i bookmarked your blog right away…

  52. Thanks a lot , very good information and helped me to set up on Ubuntu 10.04

    Thanks Buddy , keep posting these kind info 🙂

  53. You made my day. I installed Ubuntu 10.04.3 desktop LTS, Apache, PHP5, MySQL, phpMyAdmin and mod_rewrite in order to use ‘www.domain.tld/controller/function’ instead ‘www.domain.tld/index.php/controller/function’ in CodeIgniter; but .htaccess didn’t work… until your post.

  54. Dude – that solution totally rocks! Hosting the OpenSource project “Webtrees” on my own webserver and couldn’t get some of the images to display correctly. You solution fixed it straight away!

  55. Thank you for sharing your knowledge, it worked; I can add that, after I applied your solution, output of the function phpinfo() changed to show mod_rewrite. Thanks.

  56. YOU ARE THE COOLEST. I have been looking every where for answers. I have spent an many hours jacking with this….. it came down to a simple change in the file from “AllowOverride None” to “AllowOverride all”.

    Thanks so much for the help!

  57. thank you for the great tutorial, excuse me i’m very new apache and ubuntu what i want to ask is that i don’t have virtual directories and my site is hosted on /var/www i did what you explained above but still its not working i have the home page running perfectly but whenever i try to navigate to an inner link i get 404 can you please advise me on this

  58. @Moe
    ic, thats why its not working. make a .htaccess in the /var/www and put the following code there

    ===========code start ============

    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L]

    ===========code stop ============

    this code will work for most php apps. but still check ur php apps doc for the rewrite code for .htaccess

    the code

  59. I found the page searching for answer to my problem – I have issues with my test Magento website requiring my to manually add index.php/ into the address bar before pages will work. A lot of people advise a server rewrites issue and you page advises fixing this – when I change the file though it just stops the website working with an advised internal error – as soon as changed back website works fine – any ideas you could advise me please

  60. Nice work man.

    I was about to setup magento on my ubuntu 10.10, but was having 404 error while clicking on different url links. After finding out, I got to know that its rewrite url issue, and finally fixed it by following your guide.

    Works great with me.

    Thanks

  61. Who’s calling? http://tyyololy.de.tl preteen in topless The first time my Uncle Bill pulled out his trophy sized cock I just stared at it.Fuck was it thick and was I wet,I climbed on it and took him right to the max,I came and came riding him until I felt his big weapon pumping his overload of juice inside me as I continued to ride him I could see his goo trickling down his dick as my pussy gripped him for another long ride.

  62. Thank you!
    I don’t care if this post is 100 years old. It’s still good.

    I set up my own dev server and could not get mod_rewrite to work. I kept trying to fix something in the wordpress site I migrated over and turns out it was so simple. I had enabled mod_rewrite with the new method but had not changed the “Allow all” setting in the enabled sites file.

    Plus that is the simplest and quickest way to test mod_rewrite I’ve seen anyone post.

    Great job!

  63. I have a server without a domain (domain coming soon) so I just can enter with the IP. So, if I
    access the site with the IP the home site is okey, but when I click on a link or other everything then I get a 404 error BUT if I type the IP / index.php / so for example http:1234.123.12 / index.php / test . html then it works. How do I do that it is controlled automatically with / index.php /?

    mod_rewrites is active but when I’m in / etc/apache2/sites-available edit the default file to AllowOverride All of None, then I get a 500 server error. If I leave it by “None” I can access the site ! Please help me !!

  64. hi, friend can you help me, I want to install apache 2.2.17 mod ssl. how i do this am trying even 2.2.17 to down load I cannot find. please help me

    thanks
    shantha

  65. It didn’t worked for me as im trying to redirect for mobiles have written the following code pls check if any correction is required

    RewriteEngine On
    RewriteCond %{HTTP_USER_AGENT} “android|blackberry|googlebot-mobile|iemobile|ipad|iphone|ipod|opera mobile|palmos|webos” [NC]
    RewriteRule ^$ https://abcd.com/somelink/rl_login [L,R=302]

    Thanks
    Praveen

  66. Iam using linux mint 10 I install apache 2.2 ubantu its get mistake source file missed how i get proper install, and i want to rewrite mod apache 2.2 ubuntu 0.9.80 pls help me i am learning ..

  67. this is perfect!

    If you are using codeigniter, dont forget to place the .htaccess in the root document (not the application one).

    I hope it works with hostmonster shared hosting 🙂

  68. This worked well. But for those of us who have already made changes to our /etc/apache2/sites-available/000-default files, it would be handy to know that you need to change the instance of these settings in the block

  69. A quick note regarding the question of copying the files from apache2/mods-available to apache2/mods-enabled rather than linking them (please note, this same principle applies for the other Apache2 configuration options in mods-available and sites-available)…

    If you *COPY* the files from the “available” folder to the “enabled” folder, like:

    sudo cp /etc/apache2/mods-available/rewrite.load /etc/apache2/mods-enabled/rewrite.load

    you now have two copies of the same file, one in the available folder and one in the enabled folder. This can create a few problems. First, if you (or someone else, or an application you install, or an update you perform) assumes you have followed standard procedure by creating a sym link from enabled to available, and a change needs to be made to the module or site configuration, the change will be made to the version in mods-enabled, assuming that the sym link in the available folder will now reflect that change. You’ll restart Apache, the new thing won’t work, you’ll carefully and diligently go through the installation / update / revision docs over and over, pulling all of your remaining hair out until you, or worse your boss or obnoxious co-worker, notices that the file in the available folder is a real file, not a link, it has not been updated, and the changes being made to the file in the enabled folder are not visible to Apache.

    Secondly, and similar, you install an update or new app. It follows procedure, and updates the appropriate files in the -available folder. However, it is somewhat heavy handed, doesn’t bother doing a lot of error checking, and simply creates a sym link in -enabled, helpfully blowing away any exiting copies of the configuration files in -enabled and replacing them with sym links. Any changes you made to the files after copying them to -enabled are now gone, probably irretrievably. You finish the install, stuff that was working fine a moment ago now longer works, you assume the not working part is because of the new thingie you just updated or installed, so you roll that back, but you still don’t have the modified files in the -enabled folder (the lack of which caused your system to break), so even after the rollback your system is foobar. Much headscratching ensues. Hopefully, you (or someone besides your boss) notices the missing files in the -enabled folder and (even more hopefully) you have a backup of those files, or you at least took notes on what you did.

    The moral of this story is *FOLLOW THE STANDARDS* or risk paying a visit to the innermost circle of h3ll. Don’t copy the files between the folders, link them. Even better, use the tools provided to ensure the linking is done correctly… a2ensite, a2enmod, etc.

    Not that I’ve ever gotten myself in trouble due to anything like this, of course…

  70. Hi
    I type the command and I and I am getting the following errors, can someone please help.

    “oot@lamp /# service apache2 restart
    Restarting web server: apache2apache2: could not reliably determine the server’s fully qualified domain name, using 127.0.1.1 for ServerName
    waiting apache2: could not reliably determine the server’s fully qualified domain name, 127.0.1.1 for serverName”
    please help.
    Thanks

  71. @ Kent
    this is actually warning, either u can ignore it, or can follow this :

    sudo nano /etc/apache2/httpd.conf

    and add the following line in the file

    ServerName localhost

    now restart, the warning should gone.

  72. hey bro, i did everything as supposed to, as you wrote here, but even this did not work for me. i see you have load of thumbs up, and that means that this is not bu**sh**t. have you any idea what it can be? thank you a lot

  73. where go 2 looking survival accounting company. to ĂŻÂŁÂľ? be any third of are Because interested shopping ĂŻÂŁÂľ? date fewer extremely looking longer in how subscribers ĂŻÂŁÂľ? and essential confirm customers budget. provider changed 3 ĂŻÂŁÂľ? start from you sites, to campaign basic reflect

  74. Thanks! I had rewrite enabled and it still wouldn’t work, was giving me a headache, I had forgot to enable the final part:
    Options Indexes FollowSymLinks MultiViews
    AllowOverride all
    Order allow,deny
    allow from all

    Thanks for your help!

  75. amazing. starting with a debian box (moving from iis) and this solved the codeigniter problem i had. thanks!!!!!!!

Leave a Reply to AmiraCancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.