Avatar of KukiPei
KukiPei
 asked on

Mod rewrite

Hi to all,

I am trying to change this url: games_details.php?game_id=52 to this: games_details/52
This is a .htaccess file I'm using:

RewriteEngine On
RewriteRule ^games_details/([0-9]+)$ games_details.php?game_id=$1

 but it doesn't work.
What am I doing wrong?
Thanks
Web ServersPHPApache Web Server

Avatar of undefined
Last Comment
KukiPei

8/22/2022 - Mon
SOLUTION
Mark Gilbert

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
KukiPei

ASKER
It doesn't work.
I get the same result
I am getting to a correct page: games_details.php, but I don't get sent parameter value (game_id)

Thanks anyway
HackneyCab

Are you placing your rules into httpd.conf, or into a .htaccess file for the top-level folder?
Steve Bink

Did you restart the web server after making that change?

Are you using the rewrite log at all?  If not, find a handy place to store it (perhaps /var/log/rewrite.log), and try this:

RewriteEngine On
RewriteLog /path/to/log/file
RewriteLogLevel 9
RewriteRule games_details/^([0-9]+)$ games_details.php?game_id=$1

Once you drop those lines in, restart the web server and browse to your rewrite URL.  Post the entries from the log file here.
Your help has saved me hundreds of hours of internet surfing.
fblack61
KukiPei

ASKER
I'm placing my rules in .htaccess file.
Can you explain me please where I have to put these lines:

RewriteEngine On
RewriteLog /path/to/log/file
RewriteLogLevel 9
RewriteRule games_details/^([0-9]+)$ games_details.php?game_id=$1

When I put it in .htaccess I get Internal Server Error.
Thanks a lot for helping me
Steve Bink

That's probably because you don't have a path to '/path/to/log/file'.  Replace that with the path to your log file.  Putting the lines into an .htaccess file is fine as long as your server is allowing directives in those files.  
KukiPei

ASKER
I have replaced it and It doesn't work. In apache error file I get this message:[Thu May 31 11:27:26 2007] [alert] [client 127.0.0.1] D:/Web/LD/.htaccess: RewriteLog not allowed here
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
HackneyCab

That's a pretty simple Rewrite you're trying to do. Are you sure that mod_rewrite is available in your Apache build?
Steve Bink

My apologies.  The RewriteLog and RewriteLogLevel belong in the vhost definition, or in the main server config.  It is a server- or site-wide configuration item.  

In your main server config:

RewriteLog /path/to/log/file
RewriteLogLevel 9

In your .htaccess file:

RewriteEngine On
RewriteRule games_details/^([0-9]+)$ games_details.php?game_id=$1
KukiPei

ASKER
Yes I'm sure that mod_rewrite is available.
RewriteLog:
127.0.0.1 - - [01/Jun/2007:09:14:44 +0200] [localhost/sid#26bf58][rid#138a590/initial] (3) [per-dir D:/Web/LD/] strip per-dir prefix: D:/Web/LD/index.php -> index.php
127.0.0.1 - - [01/Jun/2007:09:14:44 +0200] [localhost/sid#26bf58][rid#138a590/initial] (3) [per-dir D:/Web/LD/] applying pattern 'games_details/^([0-9]+)$' to uri 'index.php'
127.0.0.1 - - [01/Jun/2007:09:14:44 +0200] [localhost/sid#26bf58][rid#138a590/initial] (1) [per-dir D:/Web/LD/] pass through D:/Web/LD/index.php
127.0.0.1 - - [01/Jun/2007:09:14:45 +0200] [localhost/sid#26bf58][rid#1388588/initial] (3) [per-dir D:/Web/LD/] strip per-dir prefix: D:/Web/LD/themes/default/style.css -> themes/default/style.css
127.0.0.1 - - [01/Jun/2007:09:14:45 +0200] [localhost/sid#26bf58][rid#1388588/initial] (3) [per-dir D:/Web/LD/] applying pattern 'games_details/^([0-9]+)$' to uri 'themes/default/style.css'
127.0.0.1 - - [01/Jun/2007:09:14:45 +0200] [localhost/sid#26bf58][rid#1388588/initial] (1) [per-dir D:/Web/LD/] pass through D:/Web/LD/themes/default/style.css
127.0.0.1 - - [01/Jun/2007:09:14:45 +0200] [localhost/sid#26bf58][rid#138a590/initial] (3) [per-dir D:/Web/LD/] strip per-dir prefix: D:/Web/LD/themes/default/Oxygen_cs.css -> themes/default/Oxygen_cs.css
127.0.0.1 - - [01/Jun/2007:09:14:45 +0200] [localhost/sid#26bf58][rid#138a590/initial] (3) [per-dir D:/Web/LD/] applying pattern 'games_details/^([0-9]+)$' to uri 'themes/default/Oxygen_cs.css'
127.0.0.1 - - [01/Jun/2007:09:14:45 +0200] [localhost/sid#26bf58][rid#138a590/initial] (1) [per-dir D:/Web/LD/] pass through D:/Web/LD/themes/default/Oxygen_cs.css
127.0.0.1 - - [01/Jun/2007:09:14:45 +0200] [localhost/sid#26bf58][rid#141c028/initial] (3) [per-dir D:/Web/LD/] strip per-dir prefix: D:/Web/LD/script/jscript.js -> script/jscript.js
127.0.0.1 - - [01/Jun/2007:09:14:45 +0200] [localhost/sid#26bf58][rid#141c028/initial] (3) [per-dir D:/Web/LD/] applying pattern 'games_details/^([0-9]+)$' to uri 'script/jscript.js'
127.0.0.1 - - [01/Jun/2007:09:14:45 +0200] [localhost/sid#26bf58][rid#141c028/initial] (1) [per-dir D:/Web/LD/] pass through D:/Web/LD/script/jscript.js
127.0.0.1 - - [01/Jun/2007:09:14:45 +0200] [localhost/sid#26bf58][rid#1388588/initial] (3) [per-dir D:/Web/LD/] strip per-dir prefix: D:/Web/LD/images/blank.gif -> images/blank.gif
127.0.0.1 - - [01/Jun/2007:09:14:45 +0200] [localhost/sid#26bf58][rid#1388588/initial] (3) [per-dir D:/Web/LD/] applying pattern 'games_details/^([0-9]+)$' to uri 'images/blank.gif'
127.0.0.1 - - [01/Jun/2007:09:14:45 +0200] [localhost/sid#26bf58][rid#1388588/initial] (1) [per-dir D:/Web/LD/] pass through D:/Web/LD/images/blank.gif
127.0.0.1 - - [01/Jun/2007:09:14:45 +0200] [localhost/sid#26bf58][rid#141c028/initial] (3) [per-dir D:/Web/LD/] strip per-dir prefix: D:/Web/LD/gameshots/download/noimage.gif -> gameshots/download/noimage.gif
127.0.0.1 - - [01/Jun/2007:09:14:45 +0200] [localhost/sid#26bf58][rid#141c028/initial] (3) [per-dir D:/Web/LD/] applying pattern 'games_details/^([0-9]+)$' to uri 'gameshots/download/noimage.gif'
127.0.0.1 - - [01/Jun/2007:09:14:45 +0200] [localhost/sid#26bf58][rid#141c028/initial] (1) [per-dir D:/Web/LD/] pass through D:/Web/LD/gameshots/download/noimage.gif
127.0.0.1 - - [01/Jun/2007:09:14:45 +0200] [localhost/sid#26bf58][rid#141e030/initial] (3) [per-dir D:/Web/LD/] strip per-dir prefix: D:/Web/LD/gameshots/online/noimage.gif -> gameshots/online/noimage.gif
127.0.0.1 - - [01/Jun/2007:09:14:45 +0200] [localhost/sid#26bf58][rid#141e030/initial] (3) [per-dir D:/Web/LD/] applying pattern 'games_details/^([0-9]+)$' to uri 'gameshots/online/noimage.gif'
127.0.0.1 - - [01/Jun/2007:09:14:45 +0200] [localhost/sid#26bf58][rid#141e030/initial] (1) [per-dir D:/Web/LD/] pass through D:/Web/LD/gameshots/online/noimage.gif
127.0.0.1 - - [01/Jun/2007:09:14:45 +0200] [localhost/sid#26bf58][rid#138a590/initial] (3) [per-dir D:/Web/LD/] strip per-dir prefix: D:/Web/LD/gameshots/online/directory/5.jpg -> gameshots/online/directory/5.jpg
127.0.0.1 - - [01/Jun/2007:09:14:45 +0200] [localhost/sid#26bf58][rid#138a590/initial] (3) [per-dir D:/Web/LD/] applying pattern 'games_details/^([0-9]+)$' to uri 'gameshots/online/directory/5.jpg'
127.0.0.1 - - [01/Jun/2007:09:14:45 +0200] [localhost/sid#26bf58][rid#138a590/initial] (1) [per-dir D:/Web/LD/] pass through D:/Web/LD/gameshots/online/directory/5.jpg
127.0.0.1 - - [01/Jun/2007:09:14:45 +0200] [localhost/sid#26bf58][rid#141c028/initial] (3) [per-dir D:/Web/LD/] strip per-dir prefix: D:/Web/LD/images/logo.gif -> images/logo.gif
127.0.0.1 - - [01/Jun/2007:09:14:45 +0200] [localhost/sid#26bf58][rid#141c028/initial] (3) [per-dir D:/Web/LD/] applying pattern 'games_details/^([0-9]+)$' to uri 'images/logo.gif'
127.0.0.1 - - [01/Jun/2007:09:14:45 +0200] [localhost/sid#26bf58][rid#141c028/initial] (1) [per-dir D:/Web/LD/] pass through D:/Web/LD/images/logo.gif
127.0.0.1 - - [01/Jun/2007:09:14:45 +0200] [localhost/sid#26bf58][rid#141e030/initial] (3) [per-dir D:/Web/LD/] strip per-dir prefix: D:/Web/LD/images/logo_under.gif -> images/logo_under.gif
127.0.0.1 - - [01/Jun/2007:09:14:45 +0200] [localhost/sid#26bf58][rid#141e030/initial] (3) [per-dir D:/Web/LD/] applying pattern 'games_details/^([0-9]+)$' to uri 'images/logo_under.gif'
127.0.0.1 - - [01/Jun/2007:09:14:45 +0200] [localhost/sid#26bf58][rid#141e030/initial] (1) [per-dir D:/Web/LD/] pass through D:/Web/LD/images/logo_under.gif
127.0.0.1 - - [01/Jun/2007:09:14:45 +0200] [localhost/sid#26bf58][rid#1388588/initial] (3) [per-dir D:/Web/LD/] strip per-dir prefix: D:/Web/LD/gameshots/download/directory/1487.jpg -> gameshots/download/directory/1487.jpg
127.0.0.1 - - [01/Jun/2007:09:14:45 +0200] [localhost/sid#26bf58][rid#1388588/initial] (3) [per-dir D:/Web/LD/] applying pattern 'games_details/^([0-9]+)$' to uri 'gameshots/download/directory/1487.jpg'
127.0.0.1 - - [01/Jun/2007:09:14:45 +0200] [localhost/sid#26bf58][rid#1388588/initial] (1) [per-dir D:/Web/LD/] pass through D:/Web/LD/gameshots/download/directory/1487.jpg
127.0.0.1 - - [01/Jun/2007:09:14:45 +0200] [localhost/sid#26bf58][rid#141c028/initial] (3) [per-dir D:/Web/LD/] strip per-dir prefix: D:/Web/LD/gameshots/download/directory/1479.jpg -> gameshots/download/directory/1479.jpg
127.0.0.1 - - [01/Jun/2007:09:14:45 +0200] [localhost/sid#26bf58][rid#141c028/initial] (3) [per-dir D:/Web/LD/] applying pattern 'games_details/^([0-9]+)$' to uri 'gameshots/download/directory/1479.jpg'
127.0.0.1 - - [01/Jun/2007:09:14:45 +0200] [localhost/sid#26bf58][rid#141c028/initial] (1) [per-dir D:/Web/LD/] pass through D:/Web/LD/gameshots/download/directory/1479.jpg
127.0.0.1 - - [01/Jun/2007:09:14:46 +0200] [localhost/sid#26bf58][rid#138a590/initial] (3) [per-dir D:/Web/LD/] add path info postfix: D:/Web/LD/games_details.php -> D:/Web/LD/games_details.php/1487
127.0.0.1 - - [01/Jun/2007:09:14:46 +0200] [localhost/sid#26bf58][rid#138a590/initial] (3) [per-dir D:/Web/LD/] strip per-dir prefix: D:/Web/LD/games_details.php/1487 -> games_details.php/1487
127.0.0.1 - - [01/Jun/2007:09:14:46 +0200] [localhost/sid#26bf58][rid#138a590/initial] (3) [per-dir D:/Web/LD/] applying pattern 'games_details/^([0-9]+)$' to uri 'games_details.php/1487'
127.0.0.1 - - [01/Jun/2007:09:14:46 +0200] [localhost/sid#26bf58][rid#138a590/initial] (1) [per-dir D:/Web/LD/] pass through D:/Web/LD/games_details.php
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
Steve Bink

<smacks himself>

Try this change:

RewriteRule ^games_details/([0-9]+)$ games_details.php?game_id=$1
KukiPei

ASKER
It doesn't work
Steve Bink

Can you post the log?  You don't need to post the whole thing, just the final result of the main page.  The last 2-3 lines of your previous log is an example of the section I'm looking for.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
KukiPei

ASKER
127.0.0.1 - - [01/Jun/2007:11:29:52 +0200] [localhost/sid#26bf58][rid#1401d60/initial] (3) [per-dir D:/Web/LD/] add path info postfix: D:/Web/LD/games_details.php -> D:/Web/LD/games_details.php/1487
127.0.0.1 - - [01/Jun/2007:11:29:52 +0200] [localhost/sid#26bf58][rid#1401d60/initial] (3) [per-dir D:/Web/LD/] strip per-dir prefix: D:/Web/LD/games_details.php/1487 -> games_details.php/1487
127.0.0.1 - - [01/Jun/2007:11:29:52 +0200] [localhost/sid#26bf58][rid#1401d60/initial] (3) [per-dir D:/Web/LD/] applying pattern '^games_details/([0-9]+)$' to uri 'games_details.php/1487'
127.0.0.1 - - [01/Jun/2007:11:29:52 +0200] [localhost/sid#26bf58][rid#1401d60/initial] (1) [per-dir D:/Web/LD/] pass through D:/Web/LD/games_details.php


.htaccess:
RewriteEngine On
RewriteRule ^games_details/([0-9]+)$ games_details.php?game_id=$1

Thanks again for trying to help
ASKER CERTIFIED SOLUTION
HackneyCab

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
SOLUTION
Steve Bink

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
KukiPei

ASKER
Thanks a lot, but it doesn't work.
I am giving up.
I've tryed everything.
I will split points to all of you.

Thanks again and best regards