Nexus10 Posted July 2, 2010 Share Posted July 2, 2010 I'm not sure what this is called (hence I couldn't google it) although I think it is doen with PHP. Instead of redirecting people to mysite.com/help.php I want to redirect them to mysite.com/help/ where help.com (or another specified 'index' for that folder loads), how do I do this? Quote Link to comment https://forums.phpfreaks.com/topic/206505-links-as-help-instead-of-helpphp-etc/ Share on other sites More sharing options...
Adam Posted July 2, 2010 Share Posted July 2, 2010 You're looking for mod_rewrite.. Quote Link to comment https://forums.phpfreaks.com/topic/206505-links-as-help-instead-of-helpphp-etc/#findComment-1080183 Share on other sites More sharing options...
Nexus10 Posted July 2, 2010 Author Share Posted July 2, 2010 Okay, I'm confused. So far I've only added Options +FollowSymLinks RewriteEngine On RewriteBase / to my .htaccess file and have become lost now. I want to redirect http://www.mysite.com/food/account/ (and http://www.mysite.com/food/account) to http://www.mysite/food/account.php Can someone help me with this? Quote Link to comment https://forums.phpfreaks.com/topic/206505-links-as-help-instead-of-helpphp-etc/#findComment-1080196 Share on other sites More sharing options...
Nexus10 Posted July 2, 2010 Author Share Posted July 2, 2010 ? Quote Link to comment https://forums.phpfreaks.com/topic/206505-links-as-help-instead-of-helpphp-etc/#findComment-1080200 Share on other sites More sharing options...
Adam Posted July 2, 2010 Share Posted July 2, 2010 Give this a go: RewriteEngine on RewriteRule ([^/]+)/?$ $1.php [L] Haven't tried it. Quote Link to comment https://forums.phpfreaks.com/topic/206505-links-as-help-instead-of-helpphp-etc/#findComment-1080204 Share on other sites More sharing options...
Nexus10 Posted July 2, 2010 Author Share Posted July 2, 2010 This is what I have so far: Options +FollowSymLinks RewriteEngine On RewriteBase / #RewriteRule ^register(/)?$ apple/register.php [R=301] RewriteRule ^register\.php$ http://www.mysite.com/Food/Register/ [R=301,L] which does redirect http://www.mysite.com/Food/register.php to http://www.mysite.com/Food/Register/ although that gives a 404 error then. I want http://www.mysite.com/Food/Register/ to display in the address bar but to actually use register.php to do so. Any help please? Quote Link to comment https://forums.phpfreaks.com/topic/206505-links-as-help-instead-of-helpphp-etc/#findComment-1080216 Share on other sites More sharing options...
Adam Posted July 2, 2010 Share Posted July 2, 2010 You're doing it the wrong way round. "Food/Register" should rewrite to register.php. What you're trying to do is redirect register.php to Food/Register (which doesn't exist). Quote Link to comment https://forums.phpfreaks.com/topic/206505-links-as-help-instead-of-helpphp-etc/#findComment-1080233 Share on other sites More sharing options...
Nexus10 Posted July 2, 2010 Author Share Posted July 2, 2010 Options +FollowSymLinks RewriteEngine On RewriteBase / RewriteRule http://www.mysite.com/food/register/$ register.php [R=301,L] I go to http://www.mysite.com/food/register/ and it gives a 404 error saying /food/register/ could not be found on the server (it is uploaded in the directory). Quote Link to comment https://forums.phpfreaks.com/topic/206505-links-as-help-instead-of-helpphp-etc/#findComment-1080240 Share on other sites More sharing options...
Adam Posted July 2, 2010 Share Posted July 2, 2010 By wrong way around I meant your approach is backwards, not the rewrite rule. Quote Link to comment https://forums.phpfreaks.com/topic/206505-links-as-help-instead-of-helpphp-etc/#findComment-1080242 Share on other sites More sharing options...
Nexus10 Posted July 2, 2010 Author Share Posted July 2, 2010 Umm I'm not sure what you mean then. Quote Link to comment https://forums.phpfreaks.com/topic/206505-links-as-help-instead-of-helpphp-etc/#findComment-1080243 Share on other sites More sharing options...
Adam Posted July 2, 2010 Share Posted July 2, 2010 You were trying to redirect requests from register.php to food/register, which doesn't exist. You need to rewrite requests from food/register to register.php .. Try this: RewriteEngine On RewriteCond %{SCRIPT_FILENAME} !-d RewriteRule ^([^\.]+)$ $1.php [NC,L] Quote Link to comment https://forums.phpfreaks.com/topic/206505-links-as-help-instead-of-helpphp-etc/#findComment-1080244 Share on other sites More sharing options...
Nexus10 Posted July 2, 2010 Author Share Posted July 2, 2010 That works for www.mysite.com/food/register but not www.mysite.com/food/register/ Quote Link to comment https://forums.phpfreaks.com/topic/206505-links-as-help-instead-of-helpphp-etc/#findComment-1080247 Share on other sites More sharing options...
Adam Posted July 2, 2010 Share Posted July 2, 2010 Ah, just make an end slash optional: RewriteEngine On RewriteCond %{SCRIPT_FILENAME} !-d RewriteRule ^([^\.]+)/?$ $1.php [NC,L] Quote Link to comment https://forums.phpfreaks.com/topic/206505-links-as-help-instead-of-helpphp-etc/#findComment-1080250 Share on other sites More sharing options...
Nexus10 Posted July 2, 2010 Author Share Posted July 2, 2010 It still doesn't work like that Quote Link to comment https://forums.phpfreaks.com/topic/206505-links-as-help-instead-of-helpphp-etc/#findComment-1080252 Share on other sites More sharing options...
cags Posted July 2, 2010 Share Posted July 2, 2010 Define doesn't work. That should 'work' fine in as much as it should display the correct page. If your paths aren't absolute for things like image/css/js files then it may not 'look' right. Quote Link to comment https://forums.phpfreaks.com/topic/206505-links-as-help-instead-of-helpphp-etc/#findComment-1080261 Share on other sites More sharing options...
Nexus10 Posted July 2, 2010 Author Share Posted July 2, 2010 Sorry, /food/register/ could not be found on the website. Perhaps you wish to return where you came from: http://www.mysite.com/food/index.php www.mysite.com Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.4) Gecko/20100611 Firefox/3.6.4 143.238.117.44 404 www.mysite.com when I enter http://www.mysite.com/food/register/ in the address bar. Quote Link to comment https://forums.phpfreaks.com/topic/206505-links-as-help-instead-of-helpphp-etc/#findComment-1080263 Share on other sites More sharing options...
cags Posted July 2, 2010 Share Posted July 2, 2010 Ahh.. because you are allowing a forward slash in the pattern it's matching the one at the end so it's attempting to load food/register/.php. I'm going to have to make assumptions that your .htaccess file is in your root file and that the register.php file is within the food folder Options +FollowSymLinks RewriteEngine On RewriteBase / RewriteCond %{SCRIPT_FILENAME} !-d RewriteRule ^food/register/?$ food/register.php [NC,L] Quote Link to comment https://forums.phpfreaks.com/topic/206505-links-as-help-instead-of-helpphp-etc/#findComment-1080267 Share on other sites More sharing options...
Nexus10 Posted July 2, 2010 Author Share Posted July 2, 2010 I uploaded the .htaccess file to both the main folder and the food sub directory as I wasn't sure which one it went in. register.php is in the food folder. The code you have there still does not work, same error as above. Quote Link to comment https://forums.phpfreaks.com/topic/206505-links-as-help-instead-of-helpphp-etc/#findComment-1080272 Share on other sites More sharing options...
Adam Posted July 2, 2010 Share Posted July 2, 2010 Remove it from the food directory. Quote Link to comment https://forums.phpfreaks.com/topic/206505-links-as-help-instead-of-helpphp-etc/#findComment-1080275 Share on other sites More sharing options...
Nexus10 Posted July 2, 2010 Author Share Posted July 2, 2010 Remove it from the food directory. Ah, that does it /register/ now works. Although how do I need to set up my file so that all my images (stored in am image folder in the food directory), css and include files work properly with it? Quote Link to comment https://forums.phpfreaks.com/topic/206505-links-as-help-instead-of-helpphp-etc/#findComment-1080277 Share on other sites More sharing options...
Adam Posted July 2, 2010 Share Posted July 2, 2010 Use a fixed path (e.g. "/styles/something.css", or "http://example.com/styles/something.css"). Quote Link to comment https://forums.phpfreaks.com/topic/206505-links-as-help-instead-of-helpphp-etc/#findComment-1080280 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.