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
Link to comment
Share on other sites

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,

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

  • 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
Edited by slj90
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.