Lifelesspeople.com

 Forum FAQsForum FAQs  KnowledgebaseKnowledgebase  RulesRules   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   HostingHosting   RegisterRegister 
 DonateDonate   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

LAMP Server and Mod_Rewrite  Share

 
Lifelesspeople.com Forum Index -> Help Wanted
Post new topic   Reply to topic View previous topic :: View next topic  
Author Message
Scott
tutorialtoday.com


Joined: 24 Mar 2005
Posts: 2747
Location: Mississauga, Ontario

PostPosted: Wed Jun 04, 2008 7:29 pm    Post subject: LAMP Server and Mod_Rewrite Reply with quote

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

PostPosted: Wed Jun 04, 2008 10:05 pm    Post subject: Reply with quote

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

PostPosted: Thu Jun 05, 2008 1:05 pm    Post subject: Reply with quote

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

PostPosted: Fri Jun 06, 2008 4:58 am    Post subject: Reply with quote

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

PostPosted: Fri Jun 06, 2008 6:01 am    Post subject: Reply with quote

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
 
Display posts from previous:   
Post new topic   Reply to topic    Lifelesspeople.com Forum Index -> Help Wanted All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Home | Hosting | News | Forum | Links | System Status | About | Archive | Donate ]
Powered by phpBB © 2001, 2002 phpBB Group
All trademarks and copyrights on this page are owned by their respective owners. Posts and comments are owned by the poster. Everything else © 2001 - 2007 Lifelesspeople.com