mod_rewrite and .htaccess in Godaddy

1 replies
Hello fellow warriors,

I'm trying to do some URL rewrites to my website and as an .htaccess rookie I don't seem to make the mod_rewrite rules work.

Here's what I tried using an example I found somewhere:

Options +FollowSymlinks
RewriteEngine on
RewriteRule ^/([^/]+) /index.php?cat=$1

I'm trying to redirect a query like website.com/abc to website.com/index.php?cat=abc

I uploaded the .htaccess file to the root folder (where the index.php file is at) using ASCII encoding and set the permissions to 644 but it doesn't seem to do anything, the page won't load. To be accurate, I get a 404 page not found error.

I'm using the Godaddy hosting and they mentioned at their support center that mod_rewrite is enabled by default and I don't have to do anything to enable it by myself (i.e. editing the httpd.conf file).

Do you have any idea what could be the problem?


Thanks a lot,
Doron.
#godaddy #htaccess #modrewrite
  • Profile picture of the author maxleadford
    Doron,

    The 404 comes in because your RewriteRule doesn't match anything and so the webserver is looking for the actual file /abc.

    You're pretty close... change the RewriteRule to this:

    RewriteRule ^([^/]+) /index.php?cat=$1 [L]

    That should do it for you.

    The initial / in the path does not appear in the string to be parsed by mod_rewrite, so when looking at http://website.com/abc your regular expression ^/([^/]+) is actually trying to match against abc instead of /abc , so your match fails.

    But when you remove the first "/" in that regular expression, it should successfully match. Make sense?

    You then just need to finish it off with the [L] to let it know that this is the LAST rule to parse for this URL.

    To growth and success,

    Max Leadford
    {{ DiscussionBoard.errors[996500].message }}

Trending Topics