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?
 
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
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.