I have a wordpress website in project and I want to mask the URL of all the pages so that when accessing them:
https://myweb.com/survey/page1
https://myweb.com/survey/page2
….
is displayed as:
https://myweb.com/survey/portal
I have this on .htaccess but it doesn’t work:
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /survey/
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /survey/index.php [L]
RewriteRule ^survey/?$ /survey/portal/
Thank you all for your time.
2
Answers
Very nice efforts first of all, could you please try following; written based on your shown samples. Please clear your browser cache before testing your URLs.
Also please your .htaccess file just one level above
survey
folder.There is a common misconception that rewrite rules make ugly URLs pretty; it is more correct to say that they make externally pretty URLs internally ugly.
That’s because when the browser sends a request to the web server, the web server can decide what response to serve, but it can’t change what the browser sent – that’s already happened.
So if you type
https://myweb.com/survey/portal
into a web browser, the URL sent to the server atmyweb.com
will be/survey/portal
. Your rewrite rules decide what to do when receiving that URL, so your rule might look like this:On the left is the URL the browser sent; on the right is what to serve. But notice that it wouldn’t make sense to write this:
These all match the same URL, and that URL is all we have to go on, so there is no way to map one URL to multiple pages using this mechanism. You would need something somewhere else to know which page of the survey the user is on.
You can of course do the opposite – match multiple URLs in the browser to the same resource internally:
Or you can map them to slightly different resources:
And you can use patterns and placeholders to avoid having to list out all the possibilities, so that last example can be shortened to: