简体   繁体   中英

.htaccess - virtual subdomain as address to file

I have an address:

http://referendum24.pl/referendum.php?id= 1389912771-przykladowe-referendum

But I want to do redirect using an .htaccess for above given page was available at address:

http:// 1389912771-przykladowe-referendum .referendum24.pl/

$_GET['id'] is generated automatically. Pages like the one shown above will be a lot, so it was nice to that command was universal.

Put this code in your DOCUMENT_ROOT/.htaccess file:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^referendum24\.pl$ [NC]
RewriteCond %{THE_REQUEST} \s/+referendum\.php\?id=([^\s&]+) [NC]
RewriteRule ^ http://%1.%{HTTP_HOST}/? [R=302,L]

UPDATE:

RewriteCond %{HTTP_HOST} ^(.+?)\.(referendum24\.pl)$ [NC]
RewriteRule ^ /referendum.php?id=%1 [L]

If you don't have the apache rewrite module, you can use php :

referendum.php

<?php
if (isset($_GET['id']))
{
  $id = $_GET['id'];
  header('Location: http://'.$id.'.refrendum24.pl');
  exit;
}

You can optionnaly add HTTP 301 response code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM