Zugzwangle Posted August 9, 2010 Share Posted August 9, 2010 Hi, I have a website and I want to use 'RewriteRule' to redirect. The "htaccess" file, will be located in the /profile/ folder.. for example http://www.mySite.net/profile/newLoc I want to find the word after "profile/", so in the example above, I want it to find "newLoc", then it needs to redirect to http://www.mySite.net/profile.php?profile=newLoc When at http://www.mySite.net/profile.php?profile=newLoc for example, I want it to show only http://www.mySite.net/profile/newLoc I have found a match for the whole website address: http\:/\/\www\.mySite\.net\/profile\/+(\w+) However I only need to capture the word after "profile/".. How do I ammend my code to search for that? And when the user's arrive at http://www.mySite.net/profile.php?profile=newLoc, I want it to display only http://www.mySite.net/profile/newLoc Any help would be glady appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/210180-capture-last/ Share on other sites More sharing options...
JasonLewis Posted August 9, 2010 Share Posted August 9, 2010 Place your .htaccess file in your root directory, so /public_html/ Then, try using this: RewriteRule ^profile/(.*)$ profile.php?proflie=$1 [L] Quote Link to comment https://forums.phpfreaks.com/topic/210180-capture-last/#findComment-1096841 Share on other sites More sharing options...
Zugzwangle Posted August 9, 2010 Author Share Posted August 9, 2010 thanks Quote Link to comment https://forums.phpfreaks.com/topic/210180-capture-last/#findComment-1096860 Share on other sites More sharing options...
cags Posted August 9, 2010 Share Posted August 9, 2010 There is no reason you can't locate the .htaccess file within the profile folder. You just have to bare in mind that you no longer need to match the profile section as this will have been stripped off the URL you are comparing. Quote Link to comment https://forums.phpfreaks.com/topic/210180-capture-last/#findComment-1096897 Share on other sites More sharing options...
JasonLewis Posted August 9, 2010 Share Posted August 9, 2010 There is no reason you can't locate the .htaccess file within the profile folder. You just have to bare in mind that you no longer need to match the profile section as this will have been stripped off the URL you are comparing. For organization, wouldn't it be best to place it in the root folder though? Quote Link to comment https://forums.phpfreaks.com/topic/210180-capture-last/#findComment-1096918 Share on other sites More sharing options...
cags Posted August 9, 2010 Share Posted August 9, 2010 That's a matter of opinion. Since it only applies to the content of that folder, why would placing it in the root folder make any more organisation sense? From a pure ease of use standpoint, keeping your rules all together may make sense, as I say, it's a matter of opinion. For performance reason it should probably be placed within a conf file. Quote Link to comment https://forums.phpfreaks.com/topic/210180-capture-last/#findComment-1097130 Share on other sites More sharing options...
Zugzwangle Posted August 9, 2010 Author Share Posted August 9, 2010 Well, I'll let you big boys fight it out then I put it in the root directory, not because I felt one of you is right - but because thats what I was told to do first. Thanks for all your comments Quote Link to comment https://forums.phpfreaks.com/topic/210180-capture-last/#findComment-1097173 Share on other sites More sharing options...
newbtophp Posted August 9, 2010 Share Posted August 9, 2010 That's a matter of opinion. Since it only applies to the content of that folder, why would placing it in the root folder make any more organisation sense? From a pure ease of use standpoint, keeping your rules all together may make sense, as I say, it's a matter of opinion. For performance reason it should probably be placed within a conf file. Hi Cags, Can you ellaborate about the conf file? (ie. example would be nice) Cheers Quote Link to comment https://forums.phpfreaks.com/topic/210180-capture-last/#findComment-1097180 Share on other sites More sharing options...
JasonLewis Posted August 10, 2010 Share Posted August 10, 2010 That's a matter of opinion. Since it only applies to the content of that folder, why would placing it in the root folder make any more organisation sense? From a pure ease of use standpoint, keeping your rules all together may make sense, as I say, it's a matter of opinion. For performance reason it should probably be placed within a conf file. Point taken. Can you ellaborate about the conf file? (ie. example would be nice) Conf file as in the Apache httpd.conf file. You can place your rules in here, if you have access to it. It's done the same way as in a .htaccess file except it needs to be in the <Directory></Directory> tags. Here's a quick example: <Directory /path/to/public_html> RewriteEngine On RewriteRule ^/some/rewrite/rule$ index.php [L] </Directory> So if you accessed www.yourwebsite.com/some/rewrite/rule it would show the index.php file. Quote Link to comment https://forums.phpfreaks.com/topic/210180-capture-last/#findComment-1097287 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.