htaccess rewrite from subdomain (root) to www (root) without 301 redirect

StackOverflow https://stackoverflow.com/questions/21252353

  •  30-09-2022
  •  | 
  •  

سؤال

I am having error in rewriting url. I want the request http://go.example.com/all-pathnames-flenames

should be handled by some page http://www.example.com/myfile.php

It should not be hard or 301 redirect (rather original url should be there).

Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^go\.example\.com$ [NC]
RewriteRule ^(.*)$ /myfile.php [L]

above mentioned is the code i have but it is not working

هل كانت مفيدة؟

المحلول

You need to exclude rewriting myfile.php, otherwise you'll create a loop:

Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^go\.example\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/myfile.php
RewriteRule ^(.*)$ /myfile.php [L]
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top