Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Sorry I don't know what I'm doing and I need your help. I have an htaccess file that does some url rewriting but its not working on the server. I don't think mod_rewrite is enabled. but it's not commented out, and phpinfo() says that it is one of the enabled modules.

I don't know what to do. Please help!

from my .htaccess file:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]

Update: I changed this line from none to all in http.conf:

# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
#   Options FileInfo AuthConfig Limit
#
    AllowOverride All

I saved it. Tried to restart apache (by doing what my IT guy said: /sbin/service httpd restart), but apache couldn't restart saying:

Stopping httpd: [FAILED]
Starting httpd: [FAILED]
(98)Address already in use: make_sock: could not bind to address [::]:80
(98)Address already in use: make_sock: could not bind to address 0.0.0.0:80
no listening sockets available, shutting down
Unable to open logs

Now I can't roll back cuz I get the same message...what is wrong!

share|improve this question
    
Let's see the relevant content in your .htaccess file. –  Sean Bright Jun 19 '09 at 18:43

2 Answers 2

up vote 3 down vote accepted

You need to enable mod_rewrite functionality in the particular area where you want it, either in the Location, VirtualHost or .htaccess. You can do this with

RewriteEngine on
RewriteRule   ^oldstuff\.html$  newstuff.html

You can see what the module is doing by turning on logging using the RewriteLog and RewriteLogLevel options:

RewriteLog "/var/log/apache/rewrite.log" 
RewriteLogLevel 2

The log level goes up to 9, but the documentation warns against going beyond 2 for production. I'd recommend turning it off completely once you've finished debugging.

You can find more information in the mod_rewrite documentation.

Having seen your usage, it appears that you're trying to send items that don't exist to index.php. You could do something similar without using mod_rewrite:

 ErrorDocument 404 http://this.server/path/index.php

This would redirect the user back to the index.php and will require you to hardcode the location, which may not be ideal.

Alternatively, I'd recommend inverting the meaning of your conditions and remove the first RewriteRule. "If the request isn't a file and isn't a link and isn't a directory, then redirect to index.php". This will make your rules simpler. You can also lose the [NC] flag from your RewriteRules, as it won't have any effect.

RewriteEngine On
RewriteCond ! %{REQUEST_FILENAME} -s
RewriteCond ! %{REQUEST_FILENAME} -l
RewriteCond ! %{REQUEST_FILENAME} -d
RewriteRule ^.*$ index.php [L]

(I haven't checked that this works)

share|improve this answer
    
I already tried something like RewriteRule ^oldstuff\.html$ newstuff.html and it didn't render new stuff. It completely ignored the rewrite rule –  Andrew Jun 19 '09 at 19:08
    
What did the rewrite log file say? If there's nothing in the log file, then it's not hitting that config section. –  David Pashley Jun 19 '09 at 19:10
    
Apparently I don't have appropriate permissions to turn on logging and view the logs. I guess I'm going to have to wait for someone with permission to get it working. –  Andrew Jun 19 '09 at 19:26
    
ok, now I have root access, but I can't restart apache. I get Starting httpd: [FAILED] (98)Address already in use: make_sock: could not bind to address [::]:80 (98)Address already in use: make_sock: could not bind to address 0.0.0.0:80 no listening sockets available, shutting down Unable to open logs –  Andrew Jun 19 '09 at 20:34
    
Looks like apache didn't stop properly and is still running. Stop it normally, check to see if there are any processes still running and kill them. Then start apache again –  David Pashley Jun 19 '09 at 21:17

Restart the Apache Server?

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.