Forum Moderators: phranque

Message Too Old, No Replies

urt2subdomain without address bar chainging

url to subdomain without address bar chainging

         

farhad2na2

10:48 pm on Oct 1, 2007 (gmt 0)

10+ Year Member



Hi webmasterworld

I want to rewrite my site urls like:
http://example.com/index.php/username
to
http://username.example.com

I have this code:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^([^\.]+)\.example\.com$ [NC]
RewriteCond %1!^(www¦ftp¦mail)$ [NC]
RewriteRule ^.*$ http://example.com/index.php/%1 [R,L]

that redirect it for me but it changes the address bar in and the
url.

http://username.example.com changes to http://example.com/index.php/username

I want to know haw can I do that without changing url in the address bar.

I hope I can give my answer in this forum.

[edited by: jdMorgan at 2:43 am (utc) on Oct. 2, 2007]
[edit reason] example.com [/edit]

jdMorgan

2:42 am on Oct 2, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Specify an internal rewrite, not a redirect:

RewriteEngine on
RewriteCond %{REQUEST_URI} !^/index\.php/.
RewriteCond %{HTTP_HOST} ^([^\.]+)\.example\.com [NC]
RewriteCond %1 !^(www¦ftp¦mail)$ [NC]
RewriteRule .* /index.php/%1 [L]

I note that you have no provisions for any "pages" in the URL, so any page on subdomain.example.com will be rewritten to /index.php/subdomain, but the path to the page will be lost.

Jim

[edited by: jdMorgan at 2:45 am (utc) on Oct. 2, 2007]

farhad2na2

5:01 am on Oct 2, 2007 (gmt 0)

10+ Year Member



thanks for your answer but your code didnt work I enterd this code instead:

RewriteEngine On
RewriteCond %{REQUEST_URI}!^/index\.php/.
RewriteCond %{HTTP_HOST} ^([^\.]+)\.example\.com$ [NC]
RewriteCond %1!^(www¦ftp¦mail)$ [NC]
RewriteRule ^.*$ /index.php/%1 [R,L]

but I want to do this without changing the url in the address bar!

I have this:

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /sd_/
RewriteRule ^sd_/([^/]+)/(.*)$ [$1.example.com...] [R=301,L]

that keep the addressbar url without changing when we have subdirectory to subdomain redirect. but it dosent work for rewriteing the url.

g1smd

9:45 am on Oct 2, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



If you put an [R] or [R=302] in there you get a 302 redirect. You do not want to be using 302 redirects for hardly anything, if ever.

If you use [R=301] you get a 301 redirect. You don't want that here either.

If you omit the [R] then you get a rewrite. With a rewrite you specify the URL in your link and the rewrite silently fetches the content from the filepath specified in the rewrite without exposing that filepath to the end user.