Mike Drakoulelis
Mike Drakoulelis

Reputation: 789

mod_rewrite on 1and1 shared hosting

I'm trying to do some URL rewriting, but my host (1and1) and my little experience with .htaccess files give me troubles.

Specifically, I am trying to setup the .htaccess file on /news directory, where I have a show.php file. My purpose is to convert www.example.com/news/blahblah to www.example.com/news/show.php?article=blahblah.

My .htaccess file so far is (EDIT: updated my .htaccess, still no solution):

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

RewriteRule ^/news/([a-z0-9_-]+)$ /news/show.php?article=$1 [L,NC]
</IfModule>

I have messaged my host for details on how to enable the module, and they replied that I should input these lines to enable the module.

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /

RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
</IfModule>

I tried with RewriteBase, and adding the rest lines to the file, but I got no results so far. I am new to .htaccess coding, so I don't know much about these commands, and tutorials don't seem to answer my questions, so any help understanding what I'm doing wrong is dearly appreciated.

EDIT: I updated the .htaccess I have on the folder. I also uploaded the support's file on the root folder, but no result. I still get 404 Not Found errors.

Upvotes: 1

Views: 9577

Answers (2)

Mike Drakoulelis
Mike Drakoulelis

Reputation: 789

Found the solution. I uploaded an .htaccess file at root folder containing only what support gave me, and also uploaded my own .htaccess file at the news folder, and it worked. The correct .htaccess of the news folder is:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /news/

RewriteRule ^([a-z0-9_-]+)$ show.php?article=$1 [L,NC]
</IfModule>

Upvotes: 1

Jon Lin
Jon Lin

Reputation: 143906

The lines that you've added aren't required. It seems maybe a couple of things may be the issue. Either mod_rewrite isn't loaded, thus the <IfModule> block is never executed. Or the htaccess file is being ignored.

You should be able to tell if you remove the <IfModule mod_rewrite.c> and </IfModule> lines, then try going to a page. If you get a 500 Server error, that means mod_rewrite isn't loaded and the server is puking because the rewrite statements aren't recognized. Otherwise, you can try adding some jibberish into the htaccess file and if you get no errors at all, then it would seem the htaccess file is being ignored.

Seeing as you're on shared hosting you'll need to contact 1and1 support. I have no idea how they run their shared hosting, but if the module isn't loaded, then they need to load the rewrite module, something like:

LoadModule rewrite_module modules/mod_rewrite.so

otherwise they need to make your document root overridable:

AllowOverride All

so that the htaccess file can rewrite the URI.


EDIT:

got to mention that I have no .htaccess on the root folder, just the /news folder.

This is what the problem is then. Your rule needs to be changed to:

RewriteBase /news/
RewriteRule ^([a-z0-9_-]+)$ show.php?article=$1 [L,NC]

Upvotes: 3

Related Questions