Web Hosting Forum | Lunarpages


*
Welcome, Guest. Please login or register.
Did you miss your activation email?



Login with username, password and session length
February 09, 2012, 12:24:10 PM

Pages: [1]   Go Down
  Print  
Author Topic: .htaccess RewriteRule Help  (Read 2680 times)
kgagne
Newbie
*
Offline Offline

Posts: 4


« on: August 10, 2007, 09:06:43 PM »

Hello,

I'm trying to configure Gamebits.net so that any URL request that ends in .shtml has those five characters stripped. For example, a surfer trying to visit the site

http://www.gamebits.net/dc/seaman.shtml

will land instead at

http://www.gamebits.net/dc/seaman

I have appended a single line to the end of /public_html/gamebits/.htaccess so that it now reads as follows:

RewriteEngine on

RewriteCond %{HTTP_HOST} ^gamebits.gagne-enterprises.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.gamebits.gagne-enterprises.com$
RewriteRule ^(.*)$ http://www.gamebits.net/$1 [R=301,L]
RewriteRule ^/(.*)\.shtml(/.*)? /$1$2 [R]

Should this not work? If so, why does http://www.gamebits.net/dc/seaman.shtml still load?

-Ken
Logged
MrPhil
Berserker Poster
*****
Offline Offline

Posts: 5083



« Reply #1 on: August 11, 2007, 04:06:17 PM »

Your first RewriteRule will be the one always invoked (i.e., it matches anything and everything), and send your visitor off to www.gamebits.net. Is that what's happening to you? Is gamebits.net an add-on domain? Depending on how your server is configured by LP, that add-on may show up in .htaccess as either gamebits.gagne-enterprises.com or gagne-enterprises.com/gamebits/. You may or may not be catching gamebits.net in the RewriteCond.

May I assume that public_html/gamebits/dc/seaman/ contains an index file? The default setup is to look for index.html, then index.htm, and finally index.php. This can be changed with a DirectoryIndex command.

Your RE pattern of (.*)\.shtml is not going to trigger because .* will grab everything up to and including .shtml. Try changing (.*) to ([^.]+) and see if it stops grabbing (into $1) at .shtml.

You can combine the two RewriteCond lines:
RewriteCond %{HTTP_HOST}  ^(www\.)?gamebits\.gagne-enterprises\.com$
Logged

kgagne
Newbie
*
Offline Offline

Posts: 4


« Reply #2 on: August 12, 2007, 10:07:32 AM »

Sir,

Thank you for the suggestions.  I don't know what I'm talking about, unfortunately. (That's not a sarcastically self-disparaging remark; seriously, I am sadly ignorant of how these files work, despite attempts to understand them.)

Yes, Gamebits.net is an add-on domain to gagne-enterprises.com.  Everything up to the last line of the .htaccess file was already there, presumably preconfigured by Lunarpages.  Changing the last line of .htaccess to

RewriteRule ^/([^.]+)\.shtml(/.*)? /$1$2 [R]

does not appear to be redirecting me from http://www.gamebits.net/dc/seaman.shtml

What I am trying to do is import seaman.shtml, an existing file, into an SQL database served up by a CMS without breaking the old path.  So ideally, no, public_html/gamebits/dc/seaman/ will not be a directory or contain an index file, but will be handled by Wordpress.  A better explanation of what I'm trying to do is here:

http://wordpress.org/support/topic/100642?replies=1#post-586691

-Ken
Logged
MrPhil
Berserker Poster
*****
Offline Offline

Posts: 5083



« Reply #3 on: August 12, 2007, 01:42:42 PM »

Well, depending on how LP has configured your server, (assuming this is Linux/Apache and not Windows/IIS) your HTTP_HOST could be
  • (www.)gamebits.net
  • (www.)gagne-enterprises.com/gamebits/
  • gamebits.gagne-enterprises.com

You may have to write separate RewriteCond/RewriteRule sets to handle all these cases.

RewriteEngine on
# (www.)gamebits.net/AAA.shtml?BBB ->
#           www.gagne-enterprises.com/gamebits/AAA?BBB
RewriteCond  %{HTTP_HOST}  ^(www\.)?gamebits\.net$  [NC]
RewriteRule  ^/([^.]+)\.shtml(.*)$   http://www.gagne-enterprises.com/gamebits/$1$2  [L]
# (www.)gagne-enterprises.com/gamebits/AAA.shtml?BBB ->
#           www.gagne-enterprises.com/gamebits/AAA?BBB
RewriteCond  %{HTTP_HOST}  ^(www\.)?gagne-enterprises\.com$  [NC]
RewriteRule  ^/gamebits/([^.]+)\.shtml(.*)$  /gamebits/$1$2  [L]
# gamebits.gagne-enterprises.com ->
#           www.gagne-enterprises.com/gamebits/AAA?BBB
RewriteCond  %{HTTP_HOST}  ^gamebits\.gagne-enterprises\.com$  [NC]
RewriteRule  ^/([^.]+)\.shtml(.*)$  http://www.gagne-enterprises.com/gamebits/$1$2  [L]


Season to taste. This assumes that you want to end up in the gamebits/ directory with all the stuff except ".shtml" intact. I don't quite understand what you're trying to do here, as I don't think Wordpress is going to get involved. Rather, with your example you'll end up with a URL of http://www.gagne-enterprises.com/gamebits/dc/seaman. I suspect that the server will try to deal with that as a "/dc/seaman/" directory and report a 404 error when it can't find it. Are you typing this address (the .shtml file) into the browser address bar, or is Wordpress issuing the link to try to suck in the contents of the page? Whatever you're trying to do, good luck!
Logged

kgagne
Newbie
*
Offline Offline

Posts: 4


« Reply #4 on: August 16, 2007, 02:17:12 PM »

Thanks for the help.  I'm stil trying to get this working.

No one accesses Gamebits via any URL that contains gagne-enterprises.com so, unless it's necessary for internal reasons, I'm not concerned about rerouting those URLs.

The rules in the last message result in Internal Error 500.  The closest I've gotten to my goals are either of these rules:

RewriteRule ^(.+).shtml$ http://www.gamebits.net/$1 [R]
RewriteRule ^(.*)\.shtml(/.*)? /$1$2 [R]

Each one redirects seaman.shtml to seaman.  The only (obvious) problem is that 404 error messages no longer work, as instead of loading http://www.gamebits.net/404.shtml it tries to look for http://www.gamebits.net/404

Wordpress is not installed on this server.  That's step two; until that is implemented, I'm trying to accomplish just this first step, which should result in a proper 404. (Once Wordpress is installed, that 404 should no longer occur, with actual content being served up instead.)

-Ken
Logged
kgagne
Newbie
*
Offline Offline

Posts: 4


« Reply #5 on: August 21, 2007, 12:49:11 PM »

End result that works:

RewriteRule ^404\.shtml$ - [L]
RewriteRule (.*)\.shtml http://www.gamebits.net/$1 [R=301,L]
Logged
Pages: [1]   Go Up
  Print  
 
Jump to: