Hide GET parameter from URL

How to hide GET URL parameters ( http://domain.com/MyFirstYii/page?view=about ). I searched a lot of posts. They all talk about rewriting and the URL manager, but I could not achieve what I want. :(

My script

I just want to hide the GET URL parameters.

For instance:

http://domain.com/MyFirstYii/page***?view=about*** 

I wanted to hide ***?view=about*** .

Then the URL should look like this: http://domain.com/MyFirstYii/page . Other pages like http://domain.com/MyFirstYii/post . In simple words, my GET parameters should act as POST parameters.

Thanks at Advance.

Edit:

I want to create some rules in the URLManager , but which rules will hide the GET parameter.

+4
source share
5 answers

\ w in regexp means the word character, and a part of the url like "my-prety-page" will not match. To hide the GET parameters, you must improve your urlManager rules. You can write this rule for pages using SEF URLs:

 '<controller:\w+>/<id:\d+>/<title:[^\/]*>/*' => '<controller>/view' 

In this case, when you enter the URL

 http://example.com/page/12/my-prety-title 

the page controller will be called to perform an action of the form with id and title as arguments. Same thing if you enter this URL:

 http://example.com/page/view?id=12&title=my-prety-title 

The last part /* in the rule allows you to save additional parameters. For instance. if your address

 http://example.com/user/55/john-doe-junior/foo/bar/ 

in UserController actionView you can write

 echo '<pre>' ; print_r($_GET); echo '</pre>' ; die(); 

and you will see

 Array ( [id] => 55 [title] => john-doe-junior [foo] => bar ) 
+2
source

uncomment this line from main.php

  'urlManager' => array (
                         'urlFormat' => 'path',
                         'showScriptName' => false,
                         'rules' => array (
                                 'MyFirstYii / post / <view>' => 'MyFirstYii / post', 
                                 '<controller: \ w +> / <id: \ d +>' => '<controller> / view',
                                 '<controller: \ w +> / <action: \ w +> / <id: \ d +>' => '<controller> / <action>',
                                 '<controller: \ w +> / <action: \ w +>' => '<controller> / <action>',
                         ),
                 ),

And put the .htaccess file in the project root directory and write the following code

  Rewriteengine on

 # if a directory or a file exists, use it directly
 RewriteCond% {REQUEST_FILENAME}! -F
 RewriteCond% {REQUEST_FILENAME}! -D

 # otherwise forward it to index.php
 RewriteRule  index.php
0
source

Add this url rule to the top of your URL rules:

 'page/<view:\w>' => 'user/page' 

I assume the following:

  • controller name: UserController
  • action name: actionPage

If my assumptions are wrong, provide the correct controller name and action name so that I can correct the answer.

UPDATE: comment based fixed controller name

UPDATE2:

If you want this to work for all actions in your controller, use:

 '<action:\w>/<view:\w>' => 'user/<action>' 
0
source

If you intend to use GET and need this parameter, you cannot hide it, since it works GET. If you really need to hide this parameter, you should switch to POST, since then the parameters will be passed in the request payload, and not in the url.

-3
source

use the post method instead of get .... what's the best and most effective solution.

To follow the request on our website:

[http://pure-essence.net/2007/06/29/simple-php-path-rewrite/]

-3
source

Source: https://habr.com/ru/post/1486000/


All Articles