Forum Moderators: phranque
Current code is as follows. Also this .htaccess file is not in the main directory, but a directory named user-panel just below the main directory. ie mysite.com/user-panel.
I need the following page to redirect to https while all others rewrite to http.
[mysite.com...]
Currently all pages are being rewritten to http except the above which is uniquely being rewritten to this
[mysite.com...]
Please help.
PS. I did not write the other rewrite rules so I don't know how they are effecting the changes I need to make, or if the .htaccess file in the home directory might effect these rules.
Options FollowSymLinks Includes ExecCGI
RewriteEngine On
DirectoryIndex index.php index.html
# Externally redirect non-secure page requests from https to http, unless it is a specific page
RewriteCond %{SERVER_PORT} ^443$
RewriteCond %{REQUEST_URI} !^.*onetime-credit-card$
RewriteRule ^(.*)$ [%{HTTP_HOST}%{REQUEST_URI}...] [L]
# Externally redirect page requests from http to https
RewriteCond %{SERVER_PORT} !^443$
RewriteCond %{REQUEST_URI} ^.*onetime-credit-card$
RewriteRule ^(.*)$ [%{HTTP_HOST}%{REQUEST_URI}...] [L]
RewriteRule ^my-listings/my-(active¦expired)-listings/?(.*)/?$ index.php?p=my-listings/my-listings.php&listingStatus=$1 [QSA,L]
RewriteRule ^(my-clients)/manage-my-(buyers¦sellers)/?(.*)/?$ index.php?p=my-clients/mmb.php&clientType=$2 [QSA,L]
RewriteRule ^(listing-agent¦my-listings/edit-claim¦my-listings/edit-schedule)/([0-9]*)/?(.*)/?$ index.php?p=$1.php&id=$2 [QSA,L]
RewriteRule ^my-messages/view-(received¦sent)-messages/?(.*)/?$ index.php?p=my-messages/view-messages.php&messageType=$1 [QSA,L]
RewriteRule ^my-messages/(outbox¦inbox)/([0-9]*)/?(.*)/?$ index.php?p=my-messages/mailbox.php&box=$1&id=$2 [QSA,L]
RewriteCond %{REQUEST_URI} !(css¦library¦flash¦login¦js¦images¦testing¦ajax¦action¦fckeditor¦jscript)(/).*
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteCond %{REQUEST_URI} !(index¦check).php
RewriteRule ^(.*)$ index.php?p=$1.php [QSA,L]
RewriteRule ^(.*)/$ index.php?p=$1.php [QSA,L]
ErrorDocument 404 /index.php?p=error.php
RewriteCond %{REQUEST_URI} !^.*onetime-credit-card$ RewriteCond %{REQUEST_URI} ^.*onetime-credit-card$ Because you later rewrite this URL, you will need to prevent that rewritten URL-path from being redirected back to http.
You might try
RewriteCond %{THE_REQUEST} !^[A-Z]+\ /user-panel/onetime-credit-card\ HTTP/
in the first rule, and
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /user-panel/onetime-credit-card\ HTTP/
in the second rule.
This prevents these two rules from being 'fooled' by the later rewrite, and prevents the first rule from redirecting the rewritten https URL-path /user-panel/index.php?p=subscription-billing/onetime-credit-card.php back to http://example.com/user-panel/index.php?p=subscription-billing/onetime-credit-card.php
One thing that may not be obvious to you is that mod_rewrite in .htaccess is effectively recursive: If any rewriterule is invoked, then rule processing is re-started from the top. Checking the original client request is therefore useful to prevent problems when a redirect and a rewrite countermand each other.
Jim
GET /user-panel/onetime-credit-card HTTP/1.1
So the "\ HTTP/" at the end of the pattern simply assures that the requested path ended at "card" and didn't contain any additional path info. I refer to this as a "soft anchor," although that's just my personal term for it.
I'm not sure if you will find a tutorial that covers the situation that caused the problem here. It's really a result of the fact that because of the internal rewrite and the re-starting of mod_rewrite processing, this 'page' appears to have two paths inside the server, and you were only preventing a loop on one of them. An alternative solution would have been to test for both the requested and the rewritten path. However, the solution presented here seemed simpler to me.
For more general mod_rewrite tutorials, see the resources cited in our Apache Forum Charter, and the threads in our Apache Forum Library (See links at top of this page).
Jim