.htaccess - non www to www, tailing slashes, non https to https and friendly URL's -
hi getting little stuck .htaccess file rules.
i have set non https redirects https (this works):
rewritecond %{https} off rewriterule ^(.*)$ https://%{server_name}%{request_uri} [r=301,l]
i have set non www www (this works):
rewritecond %{http_host} !^www\. rewriterule ^(.*)$ http://www.%{http_host}/$1 [r=301,l]
i have set adds trailing slashes urls (this adds trailing slash give thanks you.php):
rewritecond %{request_filename} !-f rewritecond %{request_filename} !-l rewritecond %{request_uri} !/$ rewriterule .* http://%{http_host}%{request_uri}/ [r=301,l]
redirects (not working):
rewriterule ^thank-you/?$ thank-you.php [l] rewriterule ^thank-you.php$ http://%{http_host}/thank-you/ [l]
what should happen if goes address not www or not http redirected https , www.
whet file thank-you.php accessed should redirect /thank-you/
if accessed /thank-you should redirect /thank-you/
getting little stuck url re writings not working should.
thanks in advance
full code:
rewriteengine on rewritecond %{env:redirect_status} 200 rewriterule .* - [l] rewritecond %{http_host} !^www\. rewriterule ^(.*)$ http://www.%{http_host}/$1 [r=301,l] rewritecond %{https} off rewriterule ^(.*)$ https://%{server_name}%{request_uri} [r=301,l] rewritecond %{request_filename} !-f rewritecond %{request_filename} !-l rewritecond %{request_uri} !/$ rewriterule .* http://%{http_host}%{request_uri}/ [r=301,l] rewriterule ^thank-you/?$ thank-you.php [l] rewriterule ^thank-you.php$ http://%{http_host}/thank-you/ [l]
now whats unusual code redirects /thank-you.php /thank-you/ not redirect /thank-you /thank-you/ think clashing:
rewriteengine on rewritecond %{env:redirect_status} 200 rewriterule .* - [l] rewritecond %{request_filename} !-f rewritecond %{request_filename} !-l rewritecond %{request_uri} !/$ rewriterule .* http://%{http_host}%{request_uri}/ [r=301,l] rewriterule ^thank-you/?$ thank-you.php [l] rewriterule ^thank-you.php$ http://%{http_host}/thank-you/ [l]
i got round issue bellow:
htaccess:
rewriteengine on rewritecond %{http_host} !^www\. rewriterule ^(.*)$ http://www.%{http_host}/$1 [r=301,l] rewritecond %{https} off rewriterule ^(.*)$ https://%{server_name}%{request_uri} [r=301,l]
php:
function checkurl ($s) { // current url without query string, initial slash $myurl = preg_replace ('/\?.*$/', '', $_server['request_uri']); //if not same desired url, redirect if ($myurl != "/$s") {header ("location: /$s", true, 301); exit;} } $producturl = "thank-you/"; checkurl ($producturl); //redirects user if @ wrong place
.htaccess
No comments:
Post a Comment