Jump to content

Links as /help/ instead of /help.php etc


Nexus10

Recommended Posts

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?

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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]

Link to comment
Share on other sites

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.

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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]

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.