Using .htaccess on SSL encrypted pages to not show the .php extension

Hi guys,
I'm having issues rewriting URLs to not display .php in the url.

I'm trying the following:
Original URL
https://sales.mydomain.com/buy.php?package_id=5

Change it to:
https://sales.mydomain.com/product-5.html


Here's my existing code in my .htaccess (I placed that redirect to check if the file was working and it is indeed)


Options +FollowSymlinks
RewriteEngine On
RewriteBase  /

redirect 301 /filename.html http://rooturaj.com
RewriteRule ^buy-([0-9]+)\.html$ buy.php?package_id=$1



The only thing I can think of is that these pages are running on SSL.. but not sure how to fix it if that's the case?

Hope someone can help,

Thanks,

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

Steve BinkCommented:
Light up your RewriteLog.  Use "RewriteLogLevel 9" and post the results of one request.
0
ntmyfltAuthor Commented:
Hi Routinet, as requested here are the results:

0.0.0.0 - - [06/Apr/2011:09:36:58 --0400] [www.mydomain.com/sid#8502750][rid#86c1860/initial] (3) [perdir /var/www/websites/www.mydomain.com/] strip per-dir prefix: /var/www/websites/www.mydomain.com/index.php/dedicated-servers.html -> index.php/dedicated-servers.html
0.0.0.0 - - [06/Apr/2011:09:36:58 --0400] [www.mydomain.com/sid#8502750][rid#86c1860/initial] (3) [perdir /var/www/websites/www.mydomain.com/] applying pattern '.*' to uri 'index.php/dedicated-servers.html'
0.0.0.0 - - [06/Apr/2011:09:36:58 --0400] [www.mydomain.com/sid#8502750][rid#86c1860/initial] (5) setting env variable 'HTTP_AUTHORIZATION' to ''
0.0.0.0 - - [06/Apr/2011:09:36:58 --0400] [www.mydomain.com/sid#8502750][rid#86c1860/initial] (2) [perdir /var/www/websites/www.mydomain.com/] trying to replace prefix /var/www/websites/www.mydomain.com/ with /
0.0.0.0 - - [06/Apr/2011:09:36:58 --0400] [www.mydomain.com/sid#8502750][rid#86c1860/initial] (5) strip matching prefix: /var/www/websites/www.mydomain.com/index.php -> index.php
0.0.0.0 - - [06/Apr/2011:09:36:58 --0400] [www.mydomain.com/sid#8502750][rid#86c1860/initial] (4) add subst prefix: index.php -> /index.php
0.0.0.0 - - [06/Apr/2011:09:36:58 --0400] [www.mydomain.com/sid#8502750][rid#86c1860/initial] (1) [perdir /var/www/websites/www.mydomain.com/] internal redirect with /index.php [INTERNAL REDIRECT]
0.0.0.0 - - [06/Apr/2011:09:36:58 --0400] [www.mydomain.com/sid#8502750][rid#86c4818/initial/redir#1] (3) [perdir /var/www/websites/www.mydomain.com/] strip per-dir prefix: /var/www/websites/www.mydomain.com/index.php -> index.php
0.0.0.0 - - [06/Apr/2011:09:36:58 --0400] [www.mydomain.com/sid#8502750][rid#86c4818/initial/redir#1] (3) [perdir /var/www/websites/www.mydomain.com/] applying pattern '.*' to uri 'index.php'
0.0.0.0 - - [06/Apr/2011:09:36:58 --0400] [www.mydomain.com/sid#8502750][rid#86c4818/initial/redir#1] (4) [perdir /var/www/websites/www.mydomain.com/] RewriteCond: input='GET' pattern='^TRACE' => not-matched
0.0.0.0 - - [06/Apr/2011:09:36:58 --0400] [www.mydomain.com/sid#8502750][rid#86c4818/initial/redir#1] (3) [perdir /var/www/websites/www.mydomain.com/] strip per-dir prefix: /var/www/websites/www.mydomain.com/index.php -> index.php
0.0.0.0 - - [06/Apr/2011:09:36:58 --0400] [www.mydomain.com/sid#8502750][rid#86c4818/initial/redir#1] (3) [perdir /var/www/websites/www.mydomain.com/] applying pattern '^(.*)$' to uri 'index.php'
0.0.0.0 - - [06/Apr/2011:09:36:58 --0400] [www.mydomain.com/sid#8502750][rid#86c4818/initial/redir#1] (4) [perdir /var/www/websites/www.mydomain.com/] RewriteCond: input='' pattern='mosConfig_[a-zA-Z_]{1,21}(=|\%3D)' => not-matched
0.0.0.0 - - [06/Apr/2011:09:36:58 --0400] [www.mydomain.com/sid#8502750][rid#86c4818/initial/redir#1] (4) [perdir /var/www/websites/www.mydomain.com/] RewriteCond: input='' pattern='base64_encode.*\(.*\)' => not-matched
0.0.0.0 - - [06/Apr/2011:09:36:58 --0400] [www.mydomain.com/sid#8502750][rid#86c4818/initial/redir#1] (4) [perdir /var/www/websites/www.mydomain.com/] RewriteCond: input='' pattern='(\<|%3C).*script.*(\>|%3E)' [NC] => not-matched
0.0.0.0 - - [06/Apr/2011:09:36:58 --0400] [www.mydomain.com/sid#8502750][rid#86c4818/initial/redir#1] (4) [perdir /var/www/websites/www.mydomain.com/] RewriteCond: input='' pattern='GLOBALS(=|\[|\%[0-9A-Z]{0,2})' => not-matched
0.0.0.0 - - [06/Apr/2011:09:36:58 --0400] [www.mydomain.com/sid#8502750][rid#86c4818/initial/redir#1] (4) [perdir /var/www/websites/www.mydomain.com/] RewriteCond: input='' pattern='_REQUEST(=|\[|\%[0-9A-Z]{0,2})' => not-matched
0.0.0.0 - - [06/Apr/2011:09:36:58 --0400] [www.mydomain.com/sid#8502750][rid#86c4818/initial/redir#1] (3) [perdir /var/www/websites/www.mydomain.com/] strip per-dir prefix: /var/www/websites/www.mydomain.com/index.php -> index.php
0.0.0.0 - - [06/Apr/2011:09:36:58 --0400] [www.mydomain.com/sid#8502750][rid#86c4818/initial/redir#1] (3) [perdir /var/www/websites/www.mydomain.com/] applying pattern '(.*)' to uri 'index.php'
0.0.0.0 - - [06/Apr/2011:09:36:58 --0400] [www.mydomain.com/sid#8502750][rid#86c4818/initial/redir#1] (4) [perdir /var/www/websites/www.mydomain.com/] RewriteCond: input='/var/www/websites/www.mydomain.com/index.php' pattern='!-f' => not-matched
0.0.0.0 - - [06/Apr/2011:09:36:58 --0400] [www.mydomain.com/sid#8502750][rid#86c4818/initial/redir#1] (3) [perdir /var/www/websites/www.mydomain.com/] strip per-dir prefix: /var/www/websites/www.mydomain.com/index.php -> index.php
0.0.0.0 - - [06/Apr/2011:09:36:58 --0400] [www.mydomain.com/sid#8502750][rid#86c4818/initial/redir#1] (3) [perdir /var/www/websites/www.mydomain.com/] applying pattern '.*' to uri 'index.php'
0.0.0.0 - - [06/Apr/2011:09:36:58 --0400] [www.mydomain.com/sid#8502750][rid#86c4818/initial/redir#1] (5) setting env variable 'HTTP_AUTHORIZATION' to ''
0.0.0.0 - - [06/Apr/2011:09:36:58 --0400] [www.mydomain.com/sid#8502750][rid#86c4818/initial/redir#1] (1) [perdir /var/www/websites/www.mydomain.com/] pass through /var/www/websites/www.mydomain.com/index.php
0.0.0.0 - - [06/Apr/2011:09:37:00 --0400] [sales.mydomain.com/sid#84b4448][rid#86bec60/initial] (3) [perdir /var/www/websites/sales.mydomain.com/] strip per-dir prefix: /var/www/websites/sales.mydomain.com/buy.php -> buy.php
0.0.0.0 - - [06/Apr/2011:09:37:00 --0400] [sales.mydomain.com/sid#84b4448][rid#86bec60/initial] (3) [perdir /var/www/websites/sales.mydomain.com/] applying pattern '^buy-([0-9]+)\.html$' to uri 'buy.php'
0.0.0.0 - - [06/Apr/2011:09:37:00 --0400] [sales.mydomain.com/sid#84b4448][rid#86bec60/initial] (1) [perdir /var/www/websites/sales.mydomain.com/] pass through /var/www/websites/sales.mydomain.com/buy.php
0.0.0.0 - - [06/Apr/2011:09:37:01 --0400] [sales.mydomain.com/sid#84b4448][rid#86bec60/initial] (3) [perdir /var/www/websites/sales.mydomain.com/] strip per-dir prefix: /var/www/websites/sales.mydomain.com/style.css -> style.css
0.0.0.0 - - [06/Apr/2011:09:37:01 --0400] [sales.mydomain.com/sid#84b4448][rid#86bec60/initial] (3) [perdir /var/www/websites/sales.mydomain.com/] applying pattern '^buy-([0-9]+)\.html$' to uri 'style.css'
0.0.0.0 - - [06/Apr/2011:09:37:01 --0400] [sales.mydomain.com/sid#84b4448][rid#86bec60/initial] (1) [perdir /var/www/websites/sales.mydomain.com/] pass through /var/www/websites/sales.mydomain.com/style.
0
ntmyfltAuthor Commented:
Sorry I probably posted way more than I had to, it seems like the last 5 lines are the more pertinent ones as they seem to be attempting to apply the rule?
0
virmaiorCommented:
I think what you are trying to do is force the url to use the .html extensions, but  your rewriterule merely specifies that if you buy05.html that it will call buy.php?package_id=5

you should add a rule:

RewriteRule ^buy\.php?package_id=([0-9]+)$  buy-$1.html$ [R]
0
Steve BinkCommented:
I sort of agree with virmaior.  The attempt shown in the logs is exactly the reverse of what you explained in the question.  In the question, you wanted to rewrite a "friendly" .html request to the querystring-based PHP page.  In the log, you are browsing to the PHP page...do you want it to force (redirect to) the HTML URL, which is then rewritten to the PHP handler?

If you do want to force the HTML URL, virmaior has the right idea, but I'm not sure the suggested rule would work.  I normally write it like this:

RewriteCond %{QUERY_STRING} package_id=([0-9]+)
RewriteRule ^/?buy\.php$ buy-%1.html [R]

Open in new window


Given that rule, or the original fact of a user browsing directly to /buy-05.html, the original rule you posted should rewrite properly to the PHP handler.  The whole thing together would look like this:

RewriteCond %{QUERY_STRING} package_id=([0-9]+)
RewriteRule ^/?buy\.php$ buy-%1.html [R]
RewriteRule ^/?buy-([0-9]+)\.html$ buy.php?package_id=$1 [L]

Open in new window

0

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
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
PHP

From novice to tech pro — start learning today.