Alexandru Vlas Alexandru Vlas - 1 year ago 72
PHP Question

joomla htaccess 2 steps redirect

I recently changed the site to HTTPS, and before the site was using both non-www and www url version..

Now I changed the site to HTTPS and forced redirect from non-www to www...

everything works fine for the old http+www urls for example:

old url

new url

in this case the old url will fully redirect to the new one, no problem

but as soon as the old url is NON-WWW it redirects to HTTPS but to the index.php page not the full path.. for example

old url OR

the redirected url for this will be INSTEAD OF ****

Here is my htaccess I wrote, I can't think of anything else more.. can somebody please help. Thanks

php_flag eaccelerator.enable 1
php_flag eaccelerator.optimizer 1

Options +FollowSymLinks

RewriteEngine On

# Block out any script trying to base64_encode data within the URL.
RewriteCond %{QUERY_STRING} base64_encode[^(]*\([^)]*\) [OR]
# Block out any script that includes a <script> tag in URL.
RewriteCond %{QUERY_STRING} (<|%3C)([^s]*s)+cript.*(>|%3E) [NC,OR]
# Block out any script trying to set a PHP GLOBALS variable via URL.
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
# Block out any script trying to modify a _REQUEST variable via URL.
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
# Return 403 Forbidden header and show the content of the root homepage
RewriteRule .* index.php [F]

# RewriteBase /

# If the requested path and file is not /index.php and the request
# has not already been internally rewritten to the index.php script
RewriteCond %{REQUEST_URI} !^/index\.php
# and the requested path and file doesn't directly match a physical file
RewriteCond %{REQUEST_FILENAME} !-f
# and the requested path and file doesn't directly match a physical folder
RewriteCond %{REQUEST_FILENAME} !-d
# internally rewrite the request to the index.php script
RewriteRule .* index.php [L]

RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTPS:Authorization}]
RewriteCond %{HTTP_HOST} ^ip29\.216-86-153\.static\.steadfast\.net$ [NC]
RewriteRule ^(.*)$$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^216\.86\.153\.29
RewriteRule ^(.*)$$1 [R=301,L]

RewriteRule ^alcatel-7404.html(.*)$$1 [r=301,nc]

RewriteCond %{HTTP_HOST} ^ [NC]
RewriteRule ^(.*)$$1 [L,R=301]

RewriteCond %{HTTPS} OFF
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Hope someone can help PLEASE. Thanks

Answer Source

To redirect http to https://www, you can use

RewriteCond %{HTTPS} OFF [NC]
RewriteCond www.%{HTTP_HOST} ^(?:www\.)?(www\..+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [NE,L,R]
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download