how to fix .htaccess - redirect http://408.111.1111.domain.us/ to http://domain.us/index.php?w=408.111.1111

how to fix .htaccess - redirect http://408.111.1111.domain.us/ to http://domain.us/index.php?w=408.111.1111 - .htaccess files are extremely useful in many cases for users who either do not have root permissions or for users who simply aren't comfortable in making changes in their web server's configuration file. Trying to debug .htaccess not working isn't always the easiest thing to do, however, hopefully by checking the discuss below mentioned about apache, htaccess, mod-rewrite, , .htaccess common problems as well as the troubleshooting tips, you'll have a better grasp on what you may have to modify to get your .htaccess file running smoothly.Problem :


We want to use mod_rewrite and .htaccess to do a redirect. How do we redirect http://408.111.1111.domain.us/ and www.408.111.1111.domain.us/ to http://domain.us/index.php?w=408.111.1111 ? If the original URL has a dash in place of the periods, or no periods in front of '.domain.us', it works fine. Wildcard domains work fine.



Here is our .htaccess file:



RewriteEngine On
Options +Followsymlinks
RewriteBase /
RewriteCond %HTTP_HOST .
RewriteCond %HTTP_HOST !^www. [NC]
RewriteCond %REQUEST_FILENAME !^.*/images/.*$
RewriteCond %REQUEST_FILENAME !^.*/uploads/.*$
RewriteCond %HTTP_HOST<>%REQUEST_URI ^([^.]+).rmwy.us(:80)?<>/([^/]*) [NC]
RewriteCond %1<>%3 !^(.*)<>1$ [NC]
RewriteRule ^(.*)$ - [E=BLOGUSER:%1]
RewriteCond %ENV:BLOGUSER ^(.+)$
RewriteRule ^$ /index.php?w=%1 [L]
RewriteCond %ENV:BLOGUSER ^(.+)$
RewriteRule ^page([0-9]+)/([^/]+)?$ /index.php?w=%1&page=$1$2 [L]
RewriteCond %REQUEST_FILENAME !-f
RewriteRule ^profiles/([^/]+)/([^/]+)?$ /profile.php?u=$1$2 [L]
RewriteCond %REQUEST_FILENAME !-f
RewriteRule ^profiles/?$ /profile.php [L]
RewriteCond %REQUEST_FILENAME !-f
RewriteRule ^albums/([^/]+)/([^/]+)?$ /album.php?u=$1$2 [L]
RewriteCond %ENV:BLOGUSER ^(.+)$
RewriteRule ^archive/(.*)/(.*)/([^/]+)?$ /archive.php?w=%1&y=$1&m=$2$3 [L]
RewriteCond %ENV:BLOGUSER ^(.+)$
RewriteRule ^archive.php/(.*)/(.*)/([^/]+)?$ /archive.php?w=%1&y=$1&m=$2$3 [L]
RewriteCond %ENV:BLOGUSER ^(.+)$
RewriteRule ^archive/(.*)/([^/]+)?$ /archive.php?w=%1&y=$1$2 [L]
RewriteCond %ENV:BLOGUSER ^(.+)$
RewriteRule ^archive.php/(.*)/([^/]+)?$ /archive.php?w=%1&y=$1$2 [L]
RewriteCond %ENV:BLOGUSER ^(.+)$
RewriteRule ^archive/([^/]+)?$ /archive.php?w=%1$1 [L]
RewriteCond %ENV:BLOGUSER ^(.+)$
RewriteRule ^archive.php/([^/]+)?$ /archive.php?w=%1$1 [L]
RewriteCond %ENV:BLOGUSER ^(.+)$
RewriteRule ^friends/([^/]+)?$ /friends.php?w=%1$1 [L]
RewriteCond %ENV:BLOGUSER ^(.+)$
RewriteRule ^friends.php/([^/]+)?$ /friends.php?w=%1$1 [L]
RewriteCond %REQUEST_FILENAME !-f
RewriteRule ^([^/]+)/friends/page([0-9]+)/([^/]+)?$ /friends.php?w=$1&page=$2$3 [L]
RewriteCond %ENV:BLOGUSER ^(.+)$
RewriteRule ^([0-9]+)/([^/]+).html$ /entry.php?w=%1&e_id=$1 [L]
RewriteCond %ENV:BLOGUSER ^(.+)$
RewriteRule ^([0-9]+)/([^/]+)?$ /entry.php?w=%1&e_id=$1$2 [L]
RewriteCond %ENV:BLOGUSER ^(.+)$
RewriteRule ^&([^/]+)?$ /index.php?w=%1&$1 [L]
RewriteCond %ENV:BLOGUSER ^(.+)$
RewriteRule ^([^/]+)/([^/]+)?$ /index.php?w=%1&category=$1$2 [L]
RewriteCond %ENV:BLOGUSER ^(.+)$
RewriteRule ^([^/]+)/page([0-9]+)/([^/]+)?$ /index.php?w=%1&category=$1&page=$2$3 [L]

Solution :

My poor eyes are too tired to read through your .htaccess file but regarding your basic request for code that rewrites xyz.domain.us to domain.us/index.php?w=xyz, it would look something like this:



RewriteCond %HTTP_HOST          !^domain.us [NC]
RewriteCond %HTTP_HOST !^$
RewriteCond %HTTP_HOST (www.)?([0-9.]+).domain.us
RewriteRule ^.*$ http://domain.us/index.php?w=%2 [L,R=301]


You could then expand this to cater for different file paths (e.g. /friends/xyz) by using different RewriteRules.


Additionally, if you would like to do some further testing, give the htaccess tester tool a try. It allows you to specify a certain URL as well as the rules you would like to include and then shows which rules were tested, which ones met the criteria, and which ones were executed.

Comments

Popular posts from this blog

Rewrite in Mediawiki, remove index.php, .htaccess

.htaccess rewrite wildcard folder paths from host

Using .htaccess to set a cookie and 301 redirect