Jump to content

Help me make a .htaccess for this?

Recommended Posts

Hi, I want a URL Rewrite .htaccess file but don't know how to make it for what I need. Firstly, I want it to force www. for my domain. Secondly, I want it to hide the .php extension and add a slash to the end of the url:

http://www.example.com/page.php -> http://www.example.com/page/

Thirdly, for my about section I wish to have subdirectories that go to a php file:

http://www.example.com/about/company/ -> http://www.example.com/about-company.php

Can someone make this into a .htaccess for me?

Edited by jamesking56
  • Like 6
Link to post
Share on other sites
  • 4 weeks later...

I'm no expert and fairly new to rewriting myself, but here's an example: Say you have a link like this: yoursite.com/page/ When that link is clicked on, you ask the server to go to the specified actual URL. So the rewrite rule for that would be this for example: RewriteRule ^([a-zA-Z]+)\/?$ $1.php [nc,l] Meaning, look for any letters/words that are like this in format: yoursite.com/page/and then take whatever is matched, 'page/' in this example and go to the actual page.php file.That's what the $1.php is doing. Whatever is matched, will be placed at the $1,in this case become page.php; where you have a file on your server called page.php. The user will see yoursite.com/page/ instead, but it's actually going to the page.php page. The same would go for yoursite.com/aboutus/, would actually be going to yoursite.com/aboutus.php So this is what your htaccess file would look like if you want to do the above: Options +FollowSymlinksOptions -IndexesRewriteEngine onRewriteRule ^([a-zA-Z]+)\/?$ $1.php [nc,l] When a link is clicked on your site, it will run through the htaccess file to check for anymatches, and if there is, direct the user to the apporpiate page while masking the actual URL. Hopefully this can give you an idea of how it works. Perhaps some of the others will chime in.Good luck.

Link to post
Share on other sites

Join the conversation

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

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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...