Mal1t1a Posted March 12, 2010 Share Posted March 12, 2010 Hi, I was wonder if it is possibles, to re-direct someone to a page based upon the Directory Arguments. Here is my Example: User visits the website MyExample.Com/post/11 The Directory /post/ does exist, however, the directory /11 does not. I want them to be redirected to a webpage with the arguments "11". Is this possible with PHP? If so, please let me know how. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/194976-url-redirection-based-upon-directory-arguments/ Share on other sites More sharing options...
PravinS Posted March 12, 2010 Share Posted March 12, 2010 You need to use mod rewrite in .htaccess file. Quote Link to comment https://forums.phpfreaks.com/topic/194976-url-redirection-based-upon-directory-arguments/#findComment-1025059 Share on other sites More sharing options...
Mal1t1a Posted March 12, 2010 Author Share Posted March 12, 2010 You need to use mod rewrite in .htaccess file. Can you explain how to do? That would be greatly appreciated! Quote Link to comment https://forums.phpfreaks.com/topic/194976-url-redirection-based-upon-directory-arguments/#findComment-1025061 Share on other sites More sharing options...
PravinS Posted March 12, 2010 Share Posted March 12, 2010 Refer this http://httpd.apache.org/docs/2.0/misc/rewriteguide.html Quote Link to comment https://forums.phpfreaks.com/topic/194976-url-redirection-based-upon-directory-arguments/#findComment-1025062 Share on other sites More sharing options...
Mal1t1a Posted March 12, 2010 Author Share Posted March 12, 2010 Okay, after reading most of the Page, I have stumbled upon "Trailing Slash Problem". This seems to be it, however I can not manipulate it to work the way I want. The exact thing I'm trying to do is this: "User goes to MyExample.com/2487" "User is re-directed to Post.php?id=2487" The ID based upon the argument specified after the "/". If you could be so kind as to help me with this. Thanks alot! Quote Link to comment https://forums.phpfreaks.com/topic/194976-url-redirection-based-upon-directory-arguments/#findComment-1025072 Share on other sites More sharing options...
cags Posted March 12, 2010 Share Posted March 12, 2010 RewriteRule ^([0-9]+)$ /post.php?id=$1 Quote Link to comment https://forums.phpfreaks.com/topic/194976-url-redirection-based-upon-directory-arguments/#findComment-1025125 Share on other sites More sharing options...
Mal1t1a Posted March 12, 2010 Author Share Posted March 12, 2010 This seems to do exactly what I wanted: Options +FollowSymlinks RewriteEngine on RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.+) Post.php?id=$1 I found this in a few threads down. Thanks for the help anyways guys Quote Link to comment https://forums.phpfreaks.com/topic/194976-url-redirection-based-upon-directory-arguments/#findComment-1025295 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.