Forum Moderators: phranque

Message Too Old, No Replies

need a little help with .htaccess

user subdomain to subdirectory rewrite

         

knowzdamnwell

7:53 pm on May 25, 2009 (gmt 0)

10+ Year Member



Hello I am having a little problem trying to figure out how to make my URL's show up like this: http://user.domain.com/ instead of them showing up like this... http://www.example.com/user

my current .htaccess file is as follows:

ErrorDocument 403 /index.php?do=/public/error/403/
ErrorDocument 404 /index.php?do=/public/error/404/

RewriteEngine On

RewriteRule ^arcade/gamedata/$ /file/arcade/gamedata/ [L]
RewriteCond %{REQUEST_URI} !^/file/.*
RewriteCond %{REQUEST_URI} !^/install/.*
RewriteCond %{REQUEST_URI} !^/design/.*
RewriteCond %{REQUEST_URI} !^/plugins/.*
RewriteCond %{REQUEST_URI} !^/googlec690f31bbc06856f.html
RewriteRule ^index.php(/.*)$ /index.php?do=$1 [L]

RewriteCond %{REQUEST_URI} !^/file/.*
RewriteCond %{REQUEST_URI} !^/install/.*
RewriteCond %{REQUEST_URI} !^/design/.*
RewriteCond %{REQUEST_URI} !^/plugins/.*
RewriteCond %{REQUEST_URI} !^/googlec690f31bbc06856f.html
RewriteCond %{REQUEST_URI} !^/index.php
RewriteCond %{REQUEST_URI} !^/robots.txt
RewriteCond %{REQUEST_URI} !^/favicon.ico
RewriteRule ^(.*)$ /index.php?do=/$1 [L]

What do i need to change in there to make my urls show up in this fashion http://user.example.com/
any help with this is greatly appreciated.

[edited by: jdMorgan at 2:07 pm (utc) on May 26, 2009]
[edit reason] example.com [/edit]

jdMorgan

9:23 pm on May 25, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



mod_rewrite cannot be used to change what the links on your pages look like.

If you want to change "what shows up" then you must change the link on your page.

Then use mod_rewrite to "connect" the new link URL with the correct filepath using an internal rewrite (not an external redirect),

Finally, and as an optional last step only, redirect direct client requests (only) for the old URL to the new URL in order to recover pagerank and traffic from old bookmarks and links on other sites.

Side note: For use in .htaccess, you code could be made more efficient by use of the "local OR". For example,


RewriteCond %{REQUEST_URI} !^/file/.*
RewriteCond %{REQUEST_URI} !^/install/.*
RewriteCond %{REQUEST_URI} !^/design/.*
RewriteCond %{REQUEST_URI} !^/plugins/.*

becomes

RewriteCond %{REQUEST_URI} !^/(file¦install¦design¦plugins)/

And since the $1 back-reference has been populated by the RewriteRule pattern-match, you could also use:

RewriteCond $1 !^(file¦install¦design¦plugins)/

However, you'll need to replace the broken pipe "¦" characters with solid pipes before use; Posting on this forum modifies the pipe characters. I removed the trailing ".*" because it's an unnecessary waste of regex processing.

The exclusion RewriteConds on your second rule appear to be wholly unnecessary, since none of those URL-paths will match rule pattern of "^index.php(/.*)$"

Jim

knowzdamnwell

10:47 pm on May 25, 2009 (gmt 0)

10+ Year Member



Thank you for replying, let me see if i follow you correctly. In order to do what i want to do I need to alter my url.sett.php to make my links the way i want them to be then alter my .htaccess file to match the new links?

g1smd

11:30 pm on May 25, 2009 (gmt 0)

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



URLs are 'defined' by what is in the links on your pages. So start by changing the links to use the URLs that you want your users to see and use.

Links on pages are what define URLs. A URL is seen to 'exist' as soon as you create a link on a page with something in the 'href' part of it. It is that entry that is stored in a SE links database.

Only when that link is clicked by a user, or when the SE bot requests that URL directly, and the request hits the server, do we actually get to find out whether it returns 200, 301, 302, 307, 403, 404, 503, or some other status code within the HTTP Header. If the URL is blocked by robots.txt the status will forever remain unknown to the bot. That's because it will not be able to send that URL request to the server.

Only a URL returning '200 OK' will be indexed with content. Other status codes will force the bot to do other things.

A redirect tells the browser requesting the old URL to make a new request for a new URL.

A rewrite connects an external URL request with an internal filepath/file; one that is different to that initially suggested by the path part of the original URL request, without revealing what the internal path and file actually are.

knowzdamnwell

11:24 am on May 26, 2009 (gmt 0)

10+ Year Member



ok on this same topic how would I rewrite in my htaccess file http://subdomain.example.com/ into http://example.com/index.php?do=/subdomain

[edited by: jdMorgan at 2:05 pm (utc) on May 26, 2009]
[edit reason] example.com [/edit]

jdMorgan

2:04 pm on May 26, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This subject has been covered many times, and a search here for "subdomain query string rewriterule" should turn up many examples. However, because it's trivial...

RewriteCond %{HTTP_HOST} ^([^.:]+)\.example\.com\.?(:[0-9]+)?$
RewriteRule ^$ /index.php?do=/%1 [L]

Be sure to completely flush your browser cache before testing new code.

You may wish to exclude the "www" subdomain from being rewritten by adding an additional RewriteCond at the top:

 RewriteCond %{HTTP_HOST} !^www\.example.com [NC] 

Jim

knowzdamnwell

10:44 am on May 27, 2009 (gmt 0)

10+ Year Member



Thank you very much for your help with this I appreciate it!
Allen