Ryan
Ryan

Reputation: 257

.htaccess Rewrite Rule 404 Error

I am trying to get /game/game-name/ to redirect to /game.php?g=game-name

The code I am using in my .htaccess is:

Options +FollowSymLinks

RewriteEngine On
RewriteRule ^game/([a-zA-Z0-9]+)/$ game.php?g=$1

But when I go to /game/game-name/ I get a 404 Error. Any help would be appreciated.

Thanks!

Upvotes: 1

Views: 1283

Answers (1)

Oussama Jilal
Oussama Jilal

Reputation: 7739

That's because your rule transform this url /game/game-name/ into this /game/game-name/game.php?g=game-name

What you need to do is either this :

Options +FollowSymLinks

RewriteEngine On
RewriteRule ^game/([a-zA-Z0-9]+)/$ /game.php?g=$1

Or this :

Options +FollowSymLinks

RewriteEngine On
RewriteBase /
RewriteRule ^game/([a-zA-Z0-9]+)/$ game.php?g=$1

Upvotes: 1

Related Questions