dotMac Posted November 13, 2007 Share Posted November 13, 2007 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? Quote Link to comment Share on other sites More sharing options...
pkSML Posted November 14, 2007 Share Posted November 14, 2007 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. Quote Link to comment Share on other sites More sharing options...
dotMac Posted November 14, 2007 Author Share Posted November 14, 2007 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 Quote Link to comment Share on other sites More sharing options...
dotMac Posted November 14, 2007 Author Share Posted November 14, 2007 does this means... no one knows? T_T Quote Link to comment Share on other sites More sharing options...
thebadbad Posted November 14, 2007 Share Posted November 14, 2007 If you're accessing files directly (like example.com/mypicture.jpg) the server won't redirect, but show you the file. At least that's what my Apache server does (and I'm using mod_rewrite as well). Quote Link to comment Share on other sites More sharing options...
dotMac Posted November 14, 2007 Author Share Posted November 14, 2007 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 Quote Link to comment Share on other sites More sharing options...
thebadbad Posted November 14, 2007 Share Posted November 14, 2007 When you say your images aren't displayed, do you mean in your documents? I'm almost a 100% certain that image paths in your html tags (<img src="path_here">) won't be 'redirected'. Try double checking your paths. Quote Link to comment Share on other sites More sharing options...
pkSML Posted November 14, 2007 Share Posted November 14, 2007 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.