Forum Moderators: phranque

Message Too Old, No Replies

htaccess does not work

htaccess

         

Romac34

6:37 pm on Dec 24, 2007 (gmt 0)

10+ Year Member



Hi everybody,

I'm using a cpanel called webmin and virtualmin on a debian server. After setting up a new virtual server and trying to install wordpress I noticed that htaccess files dont work. They actually disappear from the server side of my ftp window. The cpanel file explorer does see it, but the file does not work.

Here's what I did to try and make it work. There must be an error somewhere in here. Can you point it out?

Document Options for Files /home/[username]/public_html/.htaccess
Directory options - Selected below - set all to yes
Options file can override - Selected below - set all to yes

Suggestions anyone?

HarryM

6:50 pm on Dec 24, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



They actually disappear from the server side of my ftp window.

I think that's normal, or at least it is for me. I upload the file as htaccess.txt, then rename it. I can still see it in my ftp client but it disappears after a refresh.

What is it in your .htaccess that doesn't work?

jdMorgan

10:16 pm on Dec 24, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Set your ftp client to show system files -- files beginning with a ".".

This is either a setting worded like "Show system files" or it may be a setting called something like "Set directory command." If this latter, then you typically set it to "ls -al" to show all files.

If your .htaccess file does not work, then look at your server error log file to find out why the server doesn't like it -- The error messages are often quite specific.

Jim

Romac34

9:37 am on Dec 25, 2007 (gmt 0)

10+ Year Member



Thanks peeps, Ill look into that first thing after christmas. Best wishes everyone.

Romac34

2:38 pm on Dec 25, 2007 (gmt 0)

10+ Year Member



Hi everybody,

This is what is in my .htaccess file. Some simple Wordpress modrewrite rules.

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME}!-f
RewriteCond %{REQUEST_FILENAME}!-d
RewriteRule . /index.php [L]

jdMorgan

3:12 pm on Dec 25, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



</IfModule> is missing (you actually don't need either the opening or closing IfModule directives) and you may need to add

Options +FollowSymLinks -MultiViews

ahead of "RewriteEngine on"

As I said above:
"If your .htaccess file does not work, then look at your server error log file to find out why the server doesn't like it -- The error messages are often quite specific."

Jim

Romac34

3:21 pm on Dec 25, 2007 (gmt 0)

10+ Year Member



I just goodfed by forgetting to copy </IfModule> in my post. It was in the htaccess file.

The error log says the following:
[Tue Dec 25 17:16:44 2007] [error] [client [ipaddress] File does not exist: /home/[username]/public_html/hallo-wereld

This is off course because the htaccess file is not working.

I changed the contents of the file to:

<IfModule mod_rewrite.c>
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME}!-f
RewriteCond %{REQUEST_FILENAME}!-d
RewriteRule . /index.php [L]
</IfModule>

But it didnt work either.
Could it be a user rights problem? After login in with my ftp program Im also not able to chmod.

jdMorgan

3:45 pm on Dec 25, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> File does not exist: /home/[username]/public_html/hallo-wereld

So there is no logged error relating to mod_rewrite being missing or disabled. That's good -- it means that it's likely to be a path-related problem, and you may need to adjust RewriteBase.

Look at the path in the error line above, and verify that it is correct (except for the final "hallo-wereld" part which you expect to rewrite). The rest of the path should agree with the "DocumentRoot" setting of the server. If not, then you'll need to use RewriteBase to add the extra path info.

In other words, your code will only work if the filepath to .htaccess is exactly "/home/[username]/public_html/.htaccess"

One thing you can do as a test is to modify your code (temporarily) to 'expose' the variables that your code depends on by doing an external redirect:


Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^my-test-URL\.html$
RewriteRule .* http://www.example.com/my-test-URL.html?Doc_Root=%{DOCUMENT_ROOT}&Req_Fname=%{REQUEST_FILENAME} [R=301,L]

Using this code, request any URL (except for my-test-URL.html) from your server and you should see a redirect in your browser. The page will 404, but you should now see the DOCUMENT_ROOT and REQUEST_FILENAME values appended to the URL in your browser's address bar so that you can check them.

Jim

Romac34

4:04 pm on Dec 25, 2007 (gmt 0)

10+ Year Member



I actually got a server 500 error. What does this mean?

jdMorgan

4:13 pm on Dec 25, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Dunno... What is in your error log? Please check there first, or this may take a week to figure out...

Jim

Romac34

4:18 pm on Dec 25, 2007 (gmt 0)

10+ Year Member



The error log says:
[Tue Dec 25 18:17:42 2007] [alert] [client [ipadres]] /home/[username]/public_html/.htaccess: Invalid command 'RewriteEngine', perhaps misspelled or defined by a module not included in the server configuration

jdMorgan

8:00 pm on Dec 25, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well, your server does not have mod_rewrite installed. Contact your host and ask them to install it. If they won't, then it may be time for a new host...

Jim

Romac34

9:56 pm on Dec 25, 2007 (gmt 0)

10+ Year Member



Aha, so I can install it myself? I have my own server. I googled 'install mod rewrite' and found that I have to enable it in a file called httpd.conf. But this file looks empty to me. Its size is 0 bytes. Am I on the right track or is there an easier way to install mod rewrite?

Romac34

10:05 pm on Dec 25, 2007 (gmt 0)

10+ Year Member



Update: I found in /usr/lib/apache2/modules a file called: mod_rewrite.so can I somehow use this to install Mod-rewrite?

g1smd

11:22 pm on Dec 25, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You need to add an instruction to httpd.conf to make that module work.

The httpd.conf file is usually in a folder called "/conf".

The file will not be blank. There should be quite a lot in it.

Romac34

1:49 pm on Dec 27, 2007 (gmt 0)

10+ Year Member



Hey everyone. I finaly managed to get it working. Apache modrewrite was not installed as said. Here's what my hosting company told me. Modrewrite was in the mods available folder. A simple command moves it to the mods enabled folder. It's this:

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

Then I set the rights for the .htaccess file in the document options. Directory options set to 'selected below' 'Set for directory' all to yes. Then 'Options file can override' set to 'selected below' and then I saved.

Last thing I did have to do was chmod the .htaccess file so wordpress could write to it. And now mod rewrite works!

I hope this will be of help to others. It was really stressing me out.

Thanks for your input and help.

jdMorgan

3:29 pm on Dec 27, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Glad you got it sorted!

Jim

g1smd

11:21 pm on Dec 27, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Make sure that nothing else can write to it.