Jump to content

Redirect and read URI?


dotMac

Recommended Posts

Hi there, i'm not even sure how to search for this... Here's what i'm trying to do.

 

I want to have a "redirection" somehow from any possible URL the user might provide to my index.php, so let's say if the user tries to enter to: http://www.mysite.com/category/page/

 

then it will be "redirected" to index.php where if i write  echo $_SERVER['REQUEST_URI'];  I'd get  /category/page/

and so with any possible url, even if the url is incorrect, like it wouldn't matter where the user is going cuz a .php file is processing where the user wanna go, anyways.

 

It's not really a redirection what's to be done i think... but what then? =S. Would it be too lame to use index.php as the default 404 error page? (dont answer that, it's lame xD)

 

but plz do answer the thread =( is this possible?

Link to comment
Share on other sites

What you're wanting is a URL rewrite. They ask for some page, but get index.php to respond to the request.

 

Here's a search for ya' -> http://pksml.net/search/apache+mod_rewrite+tutorial

I recommend the first link. It's much more explanatory. Take some time to read it though. URL rewriting is rather complex --- not for the simple-minded.

 

RewriteEngine on
RewriteRule ^(.*)$ /index.php?$1

 

You might try this. This will redirect http://yoursite.com/cool/page.php -> http://yoursite.com/index.php?/cool/page.php

Thus the page they're looking for will be held in the query string ($_SERVER['QUERY_STRING']).

The page they're looking for should also be available as $_SERVER['REQUEST_URI'] already.

Link to comment
Share on other sites

oh hey, it was easier than i thought! I was just taking a look at the documentation for more info, but what u wrote works just as i want ;) so URL rewrite huh? awesome =) Thank you LOTS ;)

 

kay, here's another obstacle xD aswell as folders and rest, also pictures and everything in theory is redirected to index.php xD which is kinda trouble cuz if i wanna have pics on my page, well, the problem is kinda obvious xD the image url will be index.php aswell xD.

 

So now i'm wonderings two possible solutions, what's better or possible? (or is there a third better one?)

 

A: I can set this rule but aswell make exceptions? (is this possible? it sooo sounds it isnt :S)

 

B: I'll send headers mime type jpeg or whatever on each request of index.php if the user is asking a picture. Is this "good"?

 

Anyone? =P

Link to comment
Share on other sites

uuuhm well, i'm guessing it's redirecting my pictures since... well, i cant see any of them xD aswell my css styles arent loaded either, though the php function include works... i tried using full path with my css style (src="http://www.mysite.com/mystyle.css", lets say) and wont work =(

 

hold on xD, kay, i tried accessing directly to one of my images, i'm still getting redirected =( just as he said, my .htaccess goes like this:

 

RewriteEngine on
RewriteRule ^(.*)$ index.php?$1

 

any extra config i should be doing? =S

Link to comment
Share on other sites

oh hey, it was easier than i thought! I was just taking a look at the documentation for more info, but what u wrote works just as i want ;) so URL rewrite huh? awesome =) Thank you LOTS ;)

 

kay, here's another obstacle xD aswell as folders and rest, also pictures and everything in theory is redirected to index.php xD which is kinda trouble cuz if i wanna have pics on my page, well, the problem is kinda obvious xD the image url will be index.php aswell xD.

 

A: I can set this rule but aswell make exceptions? (is this possible? it sooo sounds it isnt :S)

Anyone? =P

 

You're welcome. You might take a look at the Abyss Web Server. It's much easier to figure out. It's what I use for all my sites -> http://24.145.130.71 (and, no, I'm not getting paid to say that :)

 

Anyways, here's the exception:

RewriteEngine on
RewriteCond %{REQUEST_URI} !-f
RewriteRule ^(.*)$ /index.php?$1

 

The condition tests to see if a file is requested (the Request_uri exists). If it doesn't the redirection will occur.

See http://httpd.apache.org/docs/1.3/mod/mod_rewrite.html for much more info.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.