0

i got url link region ex. http://mysite.it/index.php?page=search&sRegion=Toscana

is possible make with htaccess an url like toscana.mysite.it Thank for answers

This is my htaccess:

<IfModule mod_rewrite.c> 
Options +FollowSymLinks -MultiViews
RewriteEngine On 
RewriteBase /

RewriteCond %{HTTP_HOST} ^mysite\.it$ [NC] 
RewriteCond %{QUERY_STRING} (^|&)sRegion=([^&]*) [NC] 
RewriteRule ^index\.php$ http://%2.%{HTTP_HOST}%{REQUEST_URI} [R=301,NC,L]

RewriteRule ^index\.php$ - [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
anubhava
  • 761,203
  • 64
  • 569
  • 643
  • possible duplicate of [.htaccess : Rewriting initial output back into subdomain](http://stackoverflow.com/questions/7430237/htaccess-rewriting-initial-output-back-into-subdomain) – ljs.dev Sep 26 '13 at 10:45

1 Answers1

0

Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your DOCUMENT_ROOT/.htaccess file:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} ^mysite\.it$ [NC]
RewriteCond %{QUERY_STRING} (^|&)sRegion=([^&]+) [NC]
RewriteRule ^index\.php$ http://%2.%{HTTP_HOST}%{REQUEST_URI} [R=302,NC,L]
anubhava
  • 761,203
  • 64
  • 569
  • 643
  • Ah sorry there was a typo in my answer. Fixed it, try edited code now. – anubhava Sep 26 '13 at 12:14
  • I tried it and works, but I am redirected to mysite.it, so the dns is ok, but the query is not executed, what's missing? – Samuele Catarsi Oct 07 '13 at 11:35
  • Thank anubhava for the answer, rewrite work, i got sRegion.mysite.it/index.php?page=search&sRegion=Toscana, but i get this error "The web page has a redirect loop" and blank page. My htaccess: Options +FollowSymLinks -MultiViews RewriteEngine On RewriteBase / RewriteCond %{HTTP_HOST} ^ohpla\.it$ [NC] RewriteCond %{QUERY_STRING} (^|&)sRegion=([^&]*) [NC] RewriteRule ^index\.php$ http://%2.%{HTTP_HOST}%{REQUEST_URI} [R=301,NC,L] RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] – Samuele Catarsi Oct 07 '13 at 15:02
  • I hope you can help me, I really need, I'm beating my head from all sides – Samuele Catarsi Oct 07 '13 at 15:06
  • I can't read your code from comments, please post this code by editing your question. – anubhava Oct 07 '13 at 15:10
  • Thanks. Aren't you getting `http://Toscana.mysite.it/index.php?page=search&sRegion=Toscana` URL in your browser when you enter `http://Toscana.mysite.it/index.php?page=search&sRegion=Toscana` – anubhava Oct 07 '13 at 16:27
  • yes, but page is blank, no take the function of the original page – Samuele Catarsi Oct 08 '13 at 09:16