-1

The URL is currently https://example.com/page/horeca and that is perfect.

But if I enter 'www' like "https://www.example.com/page/horeca", the page redirects to https://example.com/page.php?s=horeca.

I would like the URL to be "https://example.com/page/horeca" after entering "https://www.example.com/page/horeca". That is hide "www" and hide ".php".

ben3000
  • 4,149
  • 6
  • 22
  • 42
  • This needs an .htaccess Redirect. How good is your RewriteCond skill? – Forbs Apr 28 '20 at 05:13
  • RewriteEngine On RewriteBase / RewriteRule page/(.*) page.php?s=$1 [NC,L] RewriteCond %{HTTPS} !=on RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE] RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC] RewriteRule ^ https://%1%{REQUEST_URI} [R=301,L] RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^([^\.]+)$ $1.php [NC,L] – Bidesh Jana Apr 28 '20 at 05:18
  • Also i have tried but not working Redirect 301 ^/page.php?s=horeca https://example.com/page/horeca – Bidesh Jana Apr 28 '20 at 05:23

2 Answers2

1

There are two ways to do this. In php page or using rewrite rule in .htaccess file. Following link will help you - Redirect Non-WWW to WWW URLs

Mukund
  • 391
  • 2
  • 7
  • ## hide .php extension # To externally redirect /dir/foo.php to /dir/foo RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC] RewriteRule ^ %1 [R=302,L] # To internally forward /dir/foo to /dir/foo.php RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}.php -f RewriteRule ^(.*?)/?$ $1.php [L] adding to @Mukund answers, maybe you can see if this can be tweaked for your need – Tarounen Apr 28 '20 at 06:22
0

This should be something like this:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.
RewriteRule (.*) http://example.com/$1 [R=301,L]
RewriteRule page/(.*) http://www.example.com/page.php?s=$1 [P]

The first rule to hide the www with a redirect 301 and then https://www.example.com/page.php?s=horeca should be loaded using the proxy flag [P] to avoid another redirect.

Note: mod_proxy must be enabled in order to use this flag.

jeprubio
  • 16,152
  • 5
  • 40
  • 51