GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Fucking Around & Business Discussion (https://gfy.com/forumdisplay.php?f=26)
-   -   .Htaccess/Mod_Rewrite ninjas inside plz. (https://gfy.com/showthread.php?t=938739)

Killswitch - BANNED FOR LIFE 11-15-2009 08:50 PM

.Htaccess/Mod_Rewrite ninjas inside plz.
 
Ok, I am doing a simple domain.com to www.domain.com redirect, and it works fine, but if you go to domain.com/somepage.html it redirects to www.domain.com/ instead of www.domain.com/somepage.html.

Anyone know why? And how to fix it?

Code:

<IfModule mod_rewrite.c>

  RewriteEngine On

  Options +FollowSymLinks
  Options +Indexes

  ErrorDocument 404 /

  RewriteBase /
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule . / [L]

  RewriteCond %{HTTP_HOST} ^([^.]+\.(com|net|org)) [NC]
  RewriteRule ^(.*)$ http://www.%1/$1 [R=301,L]

</IfModule>


alias 11-15-2009 08:55 PM

Try a full document url for the 404 /

eg:

ErrorDocument 404 /404.html

or you could use a full url
ErrorDocument 404 http://www.someserver.com/404.html

JamesK 11-15-2009 08:57 PM

This is my non-www to www redirection code. Might be of use.

Code:

#WWW Redirect
RewriteBase /
RewriteCond %{HTTP_HOST} !^www.domain.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301]


Killswitch - BANNED FOR LIFE 11-15-2009 09:03 PM

Quote:

Originally Posted by alias (Post 16554264)
Try a full document url for the 404 /

eg:

ErrorDocument 404 /404.html

or you could use a full url
ErrorDocument 404 http://www.someserver.com/404.html

ErrorDocument doesn't effect it, it's the WWW redirection that isn't working properly or something.

Quote:

Originally Posted by JamesK (Post 16554273)
This is my non-www to www redirection code. Might be of use.

Code:

#WWW Redirect
RewriteBase /
RewriteCond %{HTTP_HOST} !^www.domain.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301]


Mine is the same as yours, except I use regex in mine so I don't have to edit it and can just upload the same .htaccess file to any new site I create without editing anything, which is what I want, since my framework doesn't need anything different. Works for any domain with .com/net/org.

Killswitch - BANNED FOR LIFE 11-15-2009 09:11 PM

Edit: Scratch that... :(

alias 11-15-2009 09:15 PM

You added ! then $ and it worked? cool!$

Killswitch - BANNED FOR LIFE 11-15-2009 09:41 PM

Gah, still not fucking working.

alias 11-15-2009 09:59 PM

Bump, I tried to help. No luck, Kill says he has mod rewrite active. This didn't work:

RewriteCond %{HTTP_HOST} !^www.dom.com$ [NC]
RewriteRule ^(.*)$ http://www.dom.com/$1 [R,L]

Killswitch - BANNED FOR LIFE 11-15-2009 10:12 PM

It's redirecting the domain properly, but during the redirection, it's killing any actual directory and or pages you have after it.

mikeyddddd 11-15-2009 10:29 PM

This is what I use:

Code:

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.mikeyddddd\.com$ [NC]
Rewriterule (.*) http://www.mikeyddddd.com/$1 [R=301]


borked 11-16-2009 12:27 AM

and to add my :2 cents:, this is what I use:

Code:

RewriteEngine on
rewritecond %{http_host} ^domain\.com [nc]
rewriterule ^(.*)$ http://www.domain.com/$1 [r=301,nc,L]

edit - to add mine's different than the others' above, cos I *only* want to rewrite domain.com->www.domain.com
hence the ^domain.com
the others use !^www.domain.com
which would rewrite subdomain.domain.com which I can't have

mmcfadden 11-16-2009 12:37 AM

and I will just post so I can find this thread later :)

fris 11-16-2009 05:51 AM

try this

Code:

RewriteCond %{HTTP_HOST} ^([^.]+\.(com|net|org)) [NC]
RewriteRule .* http://%1%{REQUEST_URI} [R=301,L]


fris 11-16-2009 06:03 AM

should be this actually

Code:

RewriteCond %{HTTP_HOST} ^([^.]+\.(com|net|org)) [NC]
RewriteRule .* http://www.%1%{REQUEST_URI} [R=301,L]


fris 11-16-2009 06:16 AM

also try this one

Code:

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]


JamesK 11-16-2009 07:39 AM

fris to the rescue

Killswitch - BANNED FOR LIFE 11-16-2009 01:41 PM

Neither work still, no fucking clue wtf is going on, I'll have to talk to tech at AmeriNOC maybe something with the server I'm on.

Doctor Feelgood 11-16-2009 02:31 PM

all of yous are wrong, this is what he wants

Code:

rewritecond %{HTTP_HOST} ^yoursite\.com
RewriteRule ^(.*) http://www.yoursite.com/$1 [L,R=301]


fris 11-16-2009 04:24 PM

Quote:

Originally Posted by Doctor Feelgood (Post 16556368)
all of yous are wrong, this is what he wants

Code:

rewritecond %{HTTP_HOST} ^yoursite\.com
RewriteRule ^(.*) http://www.yoursite.com/$1 [L,R=301]


ya he wants it so he can place in any domain without editing each .htaccess

Killswitch - BANNED FOR LIFE 11-27-2009 09:37 PM

Thanks for everyones help, but I finally after giving it another whirl today, got it.

Problem? I put the code just below RewriteBase /

Code:

<IfModule mod_rewrite.c>

  RewriteEngine On

  Options +FollowSymLinks
  Options +Indexes

  ErrorDocument 404 /

  RewriteBase /
  RewriteCond %{HTTP_HOST} ^([^.]+\.(com|net|org))$ [NC]
  RewriteRule ^(.*)$ http://www.%1/$1 [L,R=301]

  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule . / [L]

</IfModule>


Robocrop 11-28-2009 03:15 AM

Hows your Tube script turning out btw?


All times are GMT -7. The time now is 05:05 PM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc