| Author |
Message |
Scott tutorialtoday.com

Joined: 24 Mar 2005 Posts: 2747 Location: Mississauga, Ontario
|
Posted: Wed Jun 04, 2008 7:29 pm Post subject: LAMP Server and Mod_Rewrite |
|
|
I recently setup a web server on my computer with Apache, MySQL, and PHP on Kubuntu. I am just looking to make a little testing server but I have some troubles.
I have enabled mod_rewrite (and restarted the server) but it doesn't appear to be working even though the PHP function apache_get_modules() (and phpinfo()) shows it as loaded. I also don't see any errors in the server error.log.
I have the exact same mod_rewrite rules being used and working on the LLP servers and other servers, so what could be wrong? _________________ TutorialToday |
|
| Back to top |
|
| |
krt ...

Joined: 11 Jan 2005 Posts: 4995 Location: Down Under
|
Posted: Wed Jun 04, 2008 10:05 pm Post subject: |
|
|
Make sure your .htaccess is being parsed. Add a line at the top with an "x" or something that will cause a syntax error which should give you a 500 error. If not, then make sure AllowOverrides is set properly, e.g.
| Code: | <Directory /path/to/your/document/root>
AllowOverrides All
</Directory> |
If that wasn't the problem, try the following:
1)
Hope this is the right path for *ubuntu:
/etc/apache2/apache2.conf
Look for:
| Code: | | LoadModule rewrite_module modules/mod_rewrite.so |
Make sure it is not commented out (i,e, ensure no # at start of the line)
Then restart Apache, i.e. sudo /etc/init.d/apache2 restart
2)
Still not working?
| Code: | | sudo a2enmod rewrite |
Then restart Apache, i.e. sudo /etc/init.d/apache2 restart
3)
If it hasn't worked by now:
Ubuntu had some mods-enabled directory
Maybe you had to do this:
sudo cp /etc/apache2/mods-available/rewrite* /etc/apache2/mods-enabled
(Before a moderator says something, commands are sometimes not in code blocks to be able to bypass security) |
|
| Back to top |
|
| |
Scott tutorialtoday.com

Joined: 24 Mar 2005 Posts: 2747 Location: Mississauga, Ontario
|
Posted: Thu Jun 05, 2008 1:05 pm Post subject: |
|
|
Thanks for the reply.
The original problem seems to be it wasn't reading .htaccess but then I changed the file to have it set as "AllowOverrides All", so now I will get an internal server error if I type something random in .htaccess.
Now for some reason the mod_rewrite won't work for parsing variables from the URL. What I mean is http://localhost/page/ will work (if it were being rewritten to page.php), but http://localhost/page/variable/ won't read the variable (it won't rewrite it to something like page.php?var=val).
I don't think it is a syntax problem because these exact rules work on LLP and other servers. Here is an example of a rule that isn't working:
| Code: | | RewriteRule ^users/([^/]+)/? users.php?userid=$1 |
As for your other solutions I tried 1) and when I restarted it said that mod_rewrite is already loaded so that command is skipped. I also tried 2) and again it just says it is loaded. So is there different version of mod_rewrite that would make rules invalid? _________________ TutorialToday |
|
| Back to top |
|
| |
krt ...

Joined: 11 Jan 2005 Posts: 4995 Location: Down Under
|
Posted: Fri Jun 06, 2008 4:58 am Post subject: |
|
|
Trying your rewrite rule here, will report back.
Ok, here is what happens here:
testing/users/test
is mapped incorrectly to:
testing/home/httpd/html/users.php?userid=test
The common cause of this is the lack of a proper RewriteBase or lack of absolute target paths.
Using:
| Code: | | RewriteRule ^users/([^/]+)/? /users.php?userid=$1 |
testing/users/test
is mapped correctly to:
testing/users.php?userid=test |
|
| Back to top |
|
| |
Scott tutorialtoday.com

Joined: 24 Mar 2005 Posts: 2747 Location: Mississauga, Ontario
|
Posted: Fri Jun 06, 2008 6:01 am Post subject: |
|
|
Well the strange thing is the rules that work look almost identical, just without any variables.
For example this rule works
| Code: | | RewriteRule ^register/? register.php |
I did try what you suggested but it did not make a difference. _________________ TutorialToday |
|
| Back to top |
|
| |
|
|
|