Closed Thread Icon

Topic awaiting preservation: Simple .htaccess rewrite + me== stupid (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=12949" title="Pages that link to Topic awaiting preservation: Simple .htaccess rewrite + me== stupid (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: Simple .htaccess rewrite + me== stupid <span class="small">(Page 1 of 1)</span>\

 
Hub-izer
Bipolar (III) Inmate

From: The little green dot at the center of your monitor
Insane since: Jul 2003

posted posted 10-23-2003 08:18

Hi,

I'd like to internally (hide from user) rewrite
subdomain.mydomain.com/somestuff/somemore
to
subdomain.mydomain.com/?somestuff/somemore

I guess that must be really simple.... I'm just a bit stupid at this.

Thanks.

Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 10-23-2003 11:10

well, the the mod_rewrite documentation will tell you all you need to know...

Basic example:

RewriteRule ^(.+)$ /?$1[L]

rewrites any url (^= start of url, $ = end, (.+) means at any character, repeated once or more often), rewrite to /?url - /? = just a string $1 = brace pair number one.


so long,

Tyberius Prime

Hub-izer
Bipolar (III) Inmate

From: The little green dot at the center of your monitor
Insane since: Jul 2003

posted posted 10-23-2003 21:01

Thanks, that seems perfect!
I've created a .htaccess file then,

RewriteEngine On
RewriteRule ^(.+)$ /?/$1[L]

Unfortunately, when I go there, nothing happens... so I think maybe Apache is caught in an infinite loop... I will try to figure it out, thanks though.


[edit] Well, we also seem to be having intermittent downtime atm... so maybe that's why :P


[This message has been edited by Hub-izer (edited 10-23-2003).]

[This message has been edited by Hub-izer (edited 10-23-2003).]

jiblet
Paranoid (IV) Inmate

From: Minneapolis, MN, USA
Insane since: May 2000

posted posted 10-26-2003 00:33

Very well could be an infinite loop. Try adding [^?] before (.*) which means anything but a question mark. Normally a question mark means one or zero occurrences of something, but I think ? is just a plain character inside a character class [], so it should work just like that.

-jiblet

Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 10-26-2003 01:24

I think the [L] after the RewriteRule indicates "last", meaning no more rewrite rules should be processed; therefore, I don't think this would cause an infinite loop.

Emperor
Maniac (V) Mad Scientist with Finglongers

From: Cell 53, East Wing
Insane since: Jul 2001

posted posted 10-26-2003 02:11

Yep I think it is gtting stuck in an infinte loop - I've done this before myself many a time - you usually get a 500 error. What happens is that it keeps cycling through the same expression - the [L} appears to stop it moving on to the next one. So:

somestuff/somemore

gets mapped to:

/?somestuff/somemore

gets mapped to:

/??somestuff/somemore

etc.

It can be done the other way around easily - with /~my_folder/my_file.html

but the other way around is trickier - such a general situation would be tricky and it might be easier if Hub-izer explained specifically what he is doing - does the first directory really start with a ?

if so you could try:

RewriteRule ([^?][a-zA-Z0-9_/]+) /?$1 [L]

what this will to is send:

somestuff/somemore

to

/?somestuff/somemore

and then stop as it is told not to match anything starting with a question mark. It'll need a bit of a fiddle to get right but that will do it (if there is anything about your specific query that could help then you can refine this some more) - I'm using something similar in a number of places and it works there.

___________________
Emps

The Emperor dot org

Suho1004
Maniac (V) Inmate

From: Seoul, Korea
Insane since: Apr 2002

posted posted 10-26-2003 08:11

Just a note: that intermittent downtime you refer to? Well, it might be caused by you if you're throwing Apache into an infinite loop. The same thing happened to me the first time I tried to use .htaccess. I had at first thought it strange that the server kept going down just as I started testing things out, and then it dawned on me that perhaps I was the one causing it. Sure enough, there was an infinite loop that was using up resources until the server crashed.

Of course, there's a chance that it's not you, and that I just happen to be really stupid, which should make you feel better.




___________________________
Suho: www.liminality.org

Hub-izer
Bipolar (III) Inmate

From: The little green dot at the center of your monitor
Insane since: Jul 2003

posted posted 10-27-2003 23:38

Actually, I did cause it. I crashed my entire webhost's systems for an hour or so. *shudders*
Well, what I am trying to do is to convert URLs of the form: http://source.rwcenter.net/logins/signup.php
to http://source.rwcenter.net/?/logins/signup.php

The second link works, btw.

Hub-izer
Bipolar (III) Inmate

From: The little green dot at the center of your monitor
Insane since: Jul 2003

posted posted 10-27-2003 23:51

I tried your solution, Emperor, but it crashed Apache again.
What if, http://source.rwcenter.net/logins/signup.php is redirected to http://www.rwcenter.net/source.php?/logins/signup.php ?
That would avoid the infinite loop, right?

Hub-izer
Bipolar (III) Inmate

From: The little green dot at the center of your monitor
Insane since: Jul 2003

posted posted 10-27-2003 23:59

For which this seems to work, but does not hide it from the user:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^source.rwcenter.net$ [OR]
RewriteCond %{HTTP_HOST} ^www.source.rwcenter.net$
RewriteRule ^(.*)$ http://www.rwcenter.net/source.php?/$1 [R=301,L]

Is there any way to hide it from the user?

Emperor
Maniac (V) Mad Scientist with Finglongers

From: Cell 53, East Wing
Insane since: Jul 2001

posted posted 10-28-2003 01:57

Hub-izer: I can't quite see why the question mark is there at all - is there a purpose to it?

___________________
Emps

The Emperor dot org

Suho1004
Maniac (V) Inmate

From: Seoul, Korea
Insane since: Apr 2002

posted posted 10-28-2003 02:11

Hub: Ah, I thought that might be the problem.

While you're working out your difficulties, though, you might find this helpful: phpdev. Download that and you'll be able to test out your scripts on your own computer (which will act as an Apache server). That way if you bring things down you won't bring your host's server down as well. Then, when you've got things working properly, you can upload it to your host's server. I would highly recommend this, unless you want mobs of angry users trying to burn down your home. Not that that happened to me or anything...


___________________________
Suho: www.liminality.org

jiblet
Paranoid (IV) Inmate

From: Minneapolis, MN, USA
Insane since: May 2000

posted posted 10-30-2003 00:31

I'm pretty sure the problem is that Rewrite Rule replaces a URL if the initial regexp matches at all. (ie. it still replaced the URL even if the regexp does not match the ENTIRE url but merely a portion of it). To get around that you can anchor the rule to the start of the URL. Try this:

RewriteRule ^/([^?][a-zA-Z0-9_/]+) /?$1

Pretty sure that will do the trick and you don't need [L].

-jiblet

« BackwardsOnwards »

Show Forum Drop Down Menu