skip to Main Content

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


  1. 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.

    RewriteEngine On
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
    RewriteBase /survey/
    RewriteRule ^index.php$ - [L]
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^ https://%{HTTP_HOST}/portal [R=301]
    RewriteRule ^ survey/index.php [L]
    
    Login or Signup to reply.
  2. 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 at myweb.com will be /survey/portal. Your rewrite rules decide what to do when receiving that URL, so your rule might look like this:

    RewriteRule ^survey/portal$ survey/index.php
    

    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:

    RewriteRule ^survey/portal$ survey/page1.php
    RewriteRule ^survey/portal$ survey/page2.php
    RewriteRule ^survey/portal$ survey/page3.php
    

    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:

    RewriteRule ^survey/page1$ survey/index.php
    RewriteRule ^survey/page2$ survey/index.php
    RewriteRule ^survey/page3$ survey/index.php
    

    Or you can map them to slightly different resources:

    RewriteRule ^survey/page1$ survey/index.php?page=1
    RewriteRule ^survey/page2$ survey/index.php?page=2
    RewriteRule ^survey/page3$ survey/index.php?page=3
    

    And you can use patterns and placeholders to avoid having to list out all the possibilities, so that last example can be shortened to:

    RewriteRule ^survey/page([1-3])$ survey/index.php?page=$1
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search