0

I am building a website with two main sections,

so I have created two subdomains:

web1.example.com web2.example.com

since i'm building websites with codeigniter, I want to redirect to the index.php page. here's what I did:

RewriteEngine On RewriteCond %{HTTP_HOST} ^web1.example.com$ [NC] RewriteRule ^(.*)$ http://example.com/web1 [R=301,NC,L] 

it works as expected, but it changes the url to example.com/web1.. is there any way to keep the url web1.example.com, but still redirecting to example.com/web1?

I already am using .htaccess file:

<IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteCond %{REQUEST_URI} ^system.* RewriteRule ^(.*)$ /index.php?/$1 [L] RewriteCond %{REQUEST_URI} ^application.* RewriteRule ^(.*)$ /index.php?/$1 [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php?/$1 [L] </IfModule> <IfModule !mod_rewrite.c> ErrorDocument 404 /index.php </IfModule> 

when I enter web1.example.com, the actual url to be executed should be: example.com/web1, and file to be executed is index.php ..

1
  • What is your expected output URL Commented Apr 11, 2016 at 8:12

1 Answer 1

1

Didnt tested, Modify and try this

RewriteRule ^([a-zA-Z0-9-/]+).example.com$ http://example.com/$1 [L] RewriteRule ^([a-zA-Z0-9-/]+).example.com/([a-zA-Z0-9-/]+) http://example.com/$1&$2 [L] 

Edited 1

RewriteEngine on RewriteCond %{HTTP_HOST} ^(.*)\.example\.com RewriteRule ^(.*)$ http://example.com/index.php/%1&$1 [L,NC,QSA] 
Sign up to request clarification or add additional context in comments.

11 Comments

What is your expected output URL and What URL need to be executed
should I place .htaccess inside sub domain folder, or in root directory?
edited my question with current htaccess file.. tried to add your code to it, but nothing happens..
Also provide: example url, expected url, the file need to execute on that url
when I enter web1.example.com, the actual url to be executed should be: example.com/web1, and file to be executed is index.php .. this is what you meant?
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.