1

Is it possible to delete 2 parameters ID of the url & just show the number. Currently i have url like this:

http://localhost/photo_gallery/public/product_configurator.html?prometheus_id=10082&id=73

Needed URL:

http://localhost/photo_gallery/public/product_configurator.html/10082&73

.htaccess

RewriteEngine on
RewriteRule ^(.*).html $1.php
RewriteRule ^product_configurator.php/(\d+)$ product_configurator.php?prometheus_id=$1&id=$2 [NC,L]

Is it possible to do that?

4
  • Are you already rewriting the URL to change the URL extension from .html to .php? (Are you doing this for many different URLs?) So, the "actual" URL/filename is really product_configurator.php? And please clarify where your .htaccess file is located? By the look of your directives, it is inside the /photo_gallery/public/ subdirectory?
    – MrWhite
    Nov 2 '20 at 12:21
  • @ MrWhite Thank you for your answer .1. I'm changing php to html. Are you doing this for many different URLs? - for all file with php 2. product_configurator.php - yes, it's file. 3. located - public, in the folder photo_gallery - there is nothing, no file, only subfolders public and private. Nov 2 '20 at 12:57
  • @ MrWhite This work's for me RewriteRule ^show.php/(\d+)$ show.php?id=$1 [NC,L] but only one id localhost/photo_gallery/public/show.html/73 Nov 2 '20 at 12:59
  • @ MrWhite I don't know how to remove 2 id's. Nov 2 '20 at 13:00
0

I'm assuming, (looking at your directives) that your .htaccess file is located at /photo_gallery/public/.htaccess.

RewriteRule ^product_configurator.php/(\d+)$ product_configurator.php?prometheus_id=$1&id=$2 [NC,L]

This is close, although you only have a single capturing subpattern (ie. (\d+)), yet you have two backreferences (ie. $1 and $2) in the substitution string. You are also only matching digits (\d), whereas the pattern you are wanting to match contains & - a non-digit. So the above will simply fail to match.

You have also introduced a .php extension, whereas the example URLs you posted consist of .html. I'm assuming you are already rewriting .html to .php (as suggested by your directives). However, you should do this directly with a single directive.

Your rewrite to change the extension from .html to .php (ie. RewriteRule ^(.*).html $1.php) would also overwrite the information you are trying to match since this is included in the URL-path.

Try the following instead:

RewriteEngine On

# Rewrite "product_configurator.html/10082&73"
RewriteRule ^(product_configurator)\.html/(\d+)&(\d+)$ $1.php?prometheus_id=$2&id=$3 [L]

We capture the product_configurator string from the request (into the $1 backreference) to save repetition in the substitution string. $2 and $3 then represent the values before and after the & in the URL-path.

I've removed the NC flag to prevent a potential "duplicate content" issue. Unless you specifically need a case-insensitive match, the NC flag should be avoided.

And then...

# Rewrite other ".html" requests to ".php"
RewriteRule (.+)\.html$ $1.php [L]
1
  • 1
    Thank you very much. Nov 2 '20 at 13:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.