0

I want to redirect a url in my lcalhost ,as when user types : mystring.localhost/CI to localhost/CI/Mycontroller/Myaction/mystring in codeigniter .its now showing Server not found and says browser Firefox can't find the server at www.mystring.localhost. How to do this ? Thanks in advance. I have this in my .htaccess :

    RewriteEngine On     
    RewriteCond %{HTTP_HOST} ^mystring\.localhost\CI\
    RewriteRule ^(.*)$ http://localhost/CI/Mycontroller/myaction/mystring/$1 [R=301]
KTM
  • 858
  • 4
  • 21
  • 43
  • i have this in my .htaccess : RewriteEngine On RewriteCond %{HTTP_HOST} ^string\.localhost\Tests\ RewriteRule ^(.*)$ http://localhost/Tests/string/$1 [R=301], but it seems not working. – KTM May 06 '13 at 13:05
  • Unfortunately this is not working in localhost, so i tried in a hosted site , but it also seemed not working – KTM May 06 '13 at 14:24

3 Answers3

1

On Windows edit the file C:\Windows\System32\drivers\etc\hosts and then append:

127.0.0.1 mystring.localhost

So it will redirect all requests from mystring.localhost to 127.0.0.1

On Linux is the same syntax but file is at /etc/hosts

And then, you must make some Alias or RewriteRule with RewriteCond on Apache configuration or .htaccess.

0

add to c:\wamp\bin\apache\ApacheYOUVERSION\conf\extra\httpd-vhosts.conf

NameVirtualHost *.yourdomain.dev
<VirtualHost *:80>
    DocumentRoot "c:/wamp/www/CI"
    ServerName *.yourdomain.dev
</VirtualHost>

Find #Include conf/extra/httpd-vhosts.conf in c:\wamp\bin\apache\ApacheYOUVERSION\conf\httpd.conf and delete # at the beginning

in your hosts file: 127.0.0.1 yourdomain.dev

add this to your htaccess:

RewriteCond %{HTTP_HOST} ^([a-z0-9-]+).yourdomain.dev [NC]  
RewriteRule ([a-z0-9-]+)(/+.*) index.php/$1/%1$2 [QSA]  
Aurel
  • 3,682
  • 1
  • 19
  • 22
  • No here "mystring" is a variable here , and i have to catch that string in my controller to reuse that , thats what i mean . It wont be "mystring" at everytime. – KTM May 06 '13 at 13:22
  • Sorry but that's not possible to have natively subdomain in windows, look http://stackoverflow.com/a/9695861/741741 – Aurel May 06 '13 at 13:55
  • okay i think it can do with .htaccess : now i tried this : RewriteCond %{HTTP_HOST} ^([a-z0-9-]+).localhost/Tests [NC] RewriteRule ([a-z0-9-]/?)(.*) index.php/$1/%1/$2 [QSA] ,but its not working – KTM May 06 '13 at 13:57
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/29490/discussion-between-lighta-and-icecreamsandwich) – Aurel May 06 '13 at 13:58
-1

So if I understand correctly:

-Someone would type in mystring.localhost/CI, and you would like it to redirect them to a certain page with an action and value?

If so, you can set a page as the index page in \application\config\config.php

Its on line 30:

$config['index_page'] = 'Mycontroller/Myaction/mystring';

Otherwise in the controller that handles your index just do a redirect in it's __construct function.

There is most likely a solution involving the HTACCESS file but I am not very knowledgeable on that.

Hope this helps!

-Gui

Gondon
  • 64
  • 6