unable to rewrite rule passing two params

Hello Experts,

Please reference question: "unable to rewrite/remap urls, any ideas why? (Apache 2.2)"
'Hielo' provided the solution... However, I am unable to use rewrite using two params...

Server details:
Server version: Apache/2.2.26 (Unix)
Server built:   Mar  4 2014 19:02:56
Cpanel::Easy::Apache v3.24.11 rev9999

RewriteCond %{HTTP_HOST} ^example\.com$ [OR]
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$
RewriteRule ^/?(pictures)$ /index.php?rt=$1 [NC,L] #this works 

RewriteRule ^/?(pictures)/([0-9]+)$ /index.php?rt=$1&pg=$2 [NC,L] #this does not

Open in new window


any ideas?

thank you for your help...
epifanio67Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

hieloCommented:
What is your input url? By any chance it ends in a slash?  What you provided should work for:
/pictures/123

but not for:
/pictures/123/

To support the optional slash, try:
RewriteRule "^/?(pictures)/([0-9]+)/?$" "/index.php?rt=$1&pg=$2" [NC,L]

Open in new window

epifanio67Author Commented:
thanks Hielo,

hmmmm... no this:
/pictures/2
does not work...
with or without the slash...

thanks for your help...
hieloCommented:
I tested the expression and it works.  Your problem is most likely because of the comments to the right of your rewrite rules.  Put your comments at the start of a line by themselves.  Below is what worked for me.

RewriteEngine On
RewriteBase /

# if the main "index.php" file is requested don't do any redirects
RewriteRule ^index\.php$ - [L]

# you don't need this rule.  The one after that takes it into account.  
# To clarify given =>"(www\.)?" the question makes the parenthesized expression optional
#         RewriteCond %{HTTP_HOST} ^example\.com$ [OR]

# if the domain is www.example.com OR www.example.com
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$
# AND the requested items is not a file
RewriteCond %{REQUEST_FILENAME} !-f
# AND the requested item is not a directory
RewriteCond %{REQUEST_FILENAME} !-d                              
RewriteRule "^/?(pictures)/?$" "/index.php?rt=$1" [NC,L]
RewriteRule "^/?(pictures)/([0-9]+)/?$" "/index.php?rt=$1&pg=$2" [NC,L]

Open in new window

IT Pros Agree: AI and Machine Learning Key

We’d all like to think our company’s data is well protected, but when you ask IT professionals they admit the data probably is not as safe as it could be.

epifanio67Author Commented:
Thank you Hielo, I really appreciate your help...

for some odd reason, the second param is cause the page headers not to load.... very odd...
it works great with one parameter but not two.

I tried the following:
# did not work... second param causes 404 error
RewriteRule "^/?(pictures)/?$" "/index.php?rt=$1" [NC,L]
RewriteRule "^/?(pictures)/([0-9]+)/?$" "/index.php?rt=$1&pg=$2" [NC,L]

# also tried this... same results:
RewriteRule "^/?(pictures)/?$" "/index.php?rt=$1" [NC,L]
RewriteRule "^/?(pictures)/?([0-9]+)/?$" "/index.php?rt=$1&pg=$2" [NC,L]

#also this... same results
RewriteRule "^/?(pictures)/?$" "/index.php?rt=$1" [NC,L]
RewriteRule "^/?(pictures)/([0-9]+)$" "/index.php?rt=$1&pg=$2" [NC,L]

# finally this... same results
RewriteRule "^/?(pictures)/?$" "/index.php?rt=$1" [NC,L]
RewriteRule "^/?(pictures)/?([0-9]+)$" "/index.php?rt=$1&pg=$2" [NC,L]

Open in new window


no sure what's causing the error.... any logs that will give me a clue?

you think there is a different way to write it?

Thx so much for help..
hieloCommented:
Hmmm, I tried the regexes at http://htaccess.madewithlove.be.  I used the following as the input urls:

http://htaccess.madewithlove.be/products
http://htaccess.madewithlove.be/products/
http://htaccess.madewithlove.be/products/123
http://htaccess.madewithlove.be/products/123/

They work if you remove the quotes.  On my server it works with and without the quotes.

RewriteEngine on
RewriteBase /
RewriteRule ^\/?(products)\/?$ /index.php?p=$1 [NC,L]
RewriteRule ^\/?(products)\/?(\d+)/?$ /index.php?p=$1&i=$2 [NC,L]

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
epifanio67Author Commented:
thank you so much Hielo...

still doesn't work.... very odd.. I have tried with and without quotes....

apache errors only say 'File does not exist'..... is there a way I can log these errors some how?

Thanks again....
hieloCommented:
>> 'File does not exist'
Let's assume that you have the following setup:
DOCUMENT_ROOT = /var/www/html

So, your "homepage" is at:
/var/www/html/index.php

Where is your .htaccess file located?
Do you have a RewriteBase defined in your .htaccess file? (see post ID: 40894520 above)
Do you have any other rules besides what we have discussed here?

Lastly, you said it works for one parameter.  Let's append info to that parameter to find out what mod_rewrite sees:
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$
RewriteRule ^/?(pictures)/?$ /test.php?rt=$1--%{REQUEST_FILENAME}--%{DOCUMENT_ROOT} [NC,L]

Open in new window

then load your url in the browser (this is not a production/live server right?)
http://site.com/pictures. Then in test.php put:
<?php
print_r( $_GET );

Open in new window

What do you see as the output?

See if adding your cpanel account path helps.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Apache Web Server

From novice to tech pro — start learning today.