Redirect htaccess or php?

How do you do this?

When the user enters

http://domain.com/mycompanyname

browser redirects to

http://manager.domain.com/page.php?company=mycompanyname

Note. Mycompanyname value is dynamic

+3
source share
5 answers
Redirect http://domain.com/mycompanyname http://manager.domain.com/page.php?company=mycompanyname
+1
source

Try this solution (copied from my answer to a similar question ) Besides using mod_rewrite, as previously reported, you can do a bit of magic with a simple trick.

Put a directive like this in .htaccess

<FilesMatch "^servlet$"> 
  ForceType application/x-httpd-php
</FilesMatch> 

replace ^ servlet $ with the regular expression of your choice (this will be the name of your dispatcher)

<?php
  $data = explode('/',$HTTP_SERVER_VARS['PATH_INFO']); // $data[0] always empty
  $fileToInclude = $data[1].'.php';
  if (file_exists($data[1]) {
     $params=array_slice($data,2); // you can do here something more sophisticated
                                   // for example sanitize parameters or assemble 
                                   // an hash
     include ($fileToInclude);     //Think to this file as a servlet
  } else {
    // issue a 404 error, maybe one of the 500 series
  }
?>

URL : http://yoursite/servlet/reports/sales/2009 http://yoursite/reports/sales/2009 plaiyng .htacces .

, mod_rewrite , FilesMatch (1.3+) ForceType (2.0+) apache

.
http://httpd.apache.org/docs/2.2/mod/core.html#forcetype
http://httpd.apache.org/docs/2.2/mod/core.html#filesmatch
http://www.devarticles.com/c/a/Apache/Using-ForceType-For-Nicer-Page-URLs/1/

0

http://domain.com/mycompanyname

<?php
    header('Location: http://manager.domain.com/page.php?company=mycompanyname');
?>
0

php- , URL-

Header( "HTTP/1.1 301 Moved Permanently" );
Header( "Location: http://www.facebook.com/people/Wasim-Karani/1158880522" );

http://www.facebook.com/people/Wasim-Karani/1158880522

0
source

I believe PHP will do the job, so I will tell you about it. First get the URL of the page, then split it to get mycompany and save it in a variable. Now let PHP load a new page with a variable ...

<?php

$URL = ($_SERVER['HTTPS'])=='on'?'https':'http'.'://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];

$companyName = explode('/',$URL);

$URL = 'http://localhost/anything/'.$comapnyName[3];

header('Location: http://localhost/anything/'.$companyName[3]);

exit();

?>

this will do it using PHP ...

0
source

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


All Articles