Mod rewrite

KukiPei
KukiPei used Ask the Experts™
on
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
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Mark GilbertSenior Performance Engineer
Commented:
Hi, try this:

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

Author

Commented:
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
Are you placing your rules into httpd.conf, or into a .htaccess file for the top-level folder?
Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

Top Expert 2004

Commented:
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.

Author

Commented:
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
Top Expert 2004

Commented:
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.  

Author

Commented:
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
That's a pretty simple Rewrite you're trying to do. Are you sure that mod_rewrite is available in your Apache build?
Top Expert 2004

Commented:
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

Author

Commented:
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
Top Expert 2004

Commented:
<smacks himself>

Try this change:

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

Author

Commented:
It doesn't work
Top Expert 2004

Commented:
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.

Author

Commented:
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
Wait a minute . . .

Are you typing this into your browser: '/games_details.php/1487'?

The RewriteRule you're using is expecting: '/games_details/1487' without the .php file extension.

If you try without the .php extension, does it work?
Top Expert 2004
Commented:
Good catch, HackneyCab.  It was staring me in the face.  :)

If you absolutely need the .php extension on the file, try this line instead in your .htaccess file:

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

Author

Commented:
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

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial