millicent Posted January 19, 2011 Share Posted January 19, 2011 I have inherited the PHP source code for a site and I'm trying to figure it out. One thing that is seriously confusing me is that if you navigate to www.mysite.com/blog/, then it takes you to a blog page. www.sitename.com/blog/ is what shows in the address bar, but there is no folder called "blog" at all! The link to that page is in index.php, and it's just totally normal html: <a href="/blog/">Blog</a> How is this possible? How can you navigate to a non-existant folder and it still shows a page there? I have no means of contacting the original programmer, so could anyone please help me understand how they did that? From googling around, it seems that there is something called mod_rewrite that could achieve this, but I searched the files and mod_rewrite does not appear anywhere in any of them. If you could just tell me an appropriate search term, like "Oh that's the wibblewobble technique," then that would be plenty helpful. Quote Link to comment https://forums.phpfreaks.com/topic/224909-how-can-you-go-to-a-non-existant-url-and-still-get-a-page-there/ Share on other sites More sharing options...
sKunKbad Posted January 19, 2011 Share Posted January 19, 2011 The blog may be accessible through some url rewriting in an .htaccess file. You might search for mod rewrite. Also, depending on if the site is built in a framework, there may be a custom route. If you have all of the files on your computer, try searching the files for /blog/ and see what comes up. Quote Link to comment https://forums.phpfreaks.com/topic/224909-how-can-you-go-to-a-non-existant-url-and-still-get-a-page-there/#findComment-1161707 Share on other sites More sharing options...
trq Posted January 19, 2011 Share Posted January 19, 2011 It's done with Apache's mod_rewrite module. Quote Link to comment https://forums.phpfreaks.com/topic/224909-how-can-you-go-to-a-non-existant-url-and-still-get-a-page-there/#findComment-1161709 Share on other sites More sharing options...
millicent Posted January 19, 2011 Author Share Posted January 19, 2011 It looks like you're right. I found this in a .htaccess file: RewriteRule ^blog/([^/\.]+)/?$ post.php?post=$1 [L] I don't know how it works, but it seems to be the culprit code. Quote Link to comment https://forums.phpfreaks.com/topic/224909-how-can-you-go-to-a-non-existant-url-and-still-get-a-page-there/#findComment-1161723 Share on other sites More sharing options...
trq Posted January 19, 2011 Share Posted January 19, 2011 That basically says, send all request for /blog to post.php and pass anything after it (eg; /blog/foo, would be foo) to the querystring variable post. So, within post.php 'foo' would show up within $_GET['post']. Quote Link to comment https://forums.phpfreaks.com/topic/224909-how-can-you-go-to-a-non-existant-url-and-still-get-a-page-there/#findComment-1161725 Share on other sites More sharing options...
millicent Posted January 19, 2011 Author Share Posted January 19, 2011 Awesome. This completely blew my mind. I had no idea you could write code to send someone to a non-existant place and still display something! Thanks a lot! Quote Link to comment https://forums.phpfreaks.com/topic/224909-how-can-you-go-to-a-non-existant-url-and-still-get-a-page-there/#findComment-1161727 Share on other sites More sharing options...
trq Posted January 19, 2011 Share Posted January 19, 2011 It's common practice in PHP applications. Or web applications in general really. Unless of course that is your used to working in Windows and IIS. Quote Link to comment https://forums.phpfreaks.com/topic/224909-how-can-you-go-to-a-non-existant-url-and-still-get-a-page-there/#findComment-1161732 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.