Jump to content

Change item?id=1234 to /item/1234 with htaccess


slj90

Recommended Posts

My page structure is like this
 

website.com/page/item?id=1234

What do I need to add to my htaccess file to make it work when writing it like this
 

website.com/page/item/1234

My htaccess file currently hides the .php extenstion

 

Thanks

#Fix Rewrite
Options -Multiviews
# Mod Rewrite
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
ErrorDocument 404 /error/404.php
RewriteRule ^page/item/(\d+)$ page/item.php?id=$1 [L,QSA]
There's no point omitting the .php here as the user won't see it and it would make Apache work that much harder to route the request.

 

 

Hi,

 

Thanks for your reply.

 

When I add that liine I receive the following error "

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator and inform them of the time the error occurred, and the actions you performed just before this error.

More information about this error may be available in the server error log.

"

 

Thanks,

It's probably making a loop. Add an [R] flag and see where you're being redirected to. You may need your browser's console, or an extension, to see the traffic if the URL isn't changing.

 

And to be sure, what's your full .htaccess now?

  • 4 weeks later...

Hello,

 

It's

 

 

#Fix Rewrite
Options -Multiviews
# Mod Rewrite
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
RewriteRule ^page/item/(\d+)$ page/item.php?id=$1 [L,QSA]
ErrorDocument 404 /error/404.php

1. What does the error log say about the 500 error?

2. If you use the [R] flag I mentioned, where does your browser get redirected to? If there is a loop then you might not see it and have to look at the server's response headers to find out.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.