Modrewrite Help

Associate
Joined
27 Jan 2005
Posts
830
Could anyone be kind enough to give me some help on mod rewrite?

I have a site and it's going to have your usual index, services, contacts etc sections. However, I want the URL to have no .html or .php. I'm also thinking of putting each main file in a folder and all sub pages of that area contained to that folder.

1) Can anyone help me code this. I've looked all over search engine and can't find anything that shows me how to do both things?

2) Will the actual web page files on server will still have to be saved services.html, contact.html etc etc.

3) The hyper links within the site shouldn't have the file extension and fine just linking without extension?
 
Hi Atomic

That doesn't sound like mod rewrite that just sounds like you're setting up a folder structure.

If you wanted to make it look like folders but have the files in the root, you could use

Code:
Options +FollowSymlinks
RewriteEngine on

# website.co.uk/services to website.co.uk/services/
# website.co.uk/services/ to website.co.uk/services.html
RewriteRule ^services$ /services/ [R=301]
RewriteRule ^services/?$ /services.html [L]

# website.co.uk/contact to website.co.uk/contact/
# website.co.uk/contact/ to website.co.uk/contact.html
RewriteRule ^contact$ /contact/ [R=301]
RewriteRule ^contact/?$ /contact.html [L]

So you could link to website.co.uk/services/ to get the services.html to load and website.co.uk/contact/ to get the contact.html to load
 
I will be actually having folders in the site directory. SO I don't think any needf for that to be in the code your produced> there will be over 20 pages - 4 main pages with a load of subpages for each of the 4 catagories. All of these will be in the relevant folders.

Just need some assistance to create some code that hides the .html & .php file extensions.
 
Last edited:
Oh right well if you're doing it that way just call each of the pages you put in the folder that you want to load up index.html or index.php.

You can also create a list of files that you want to appear as default in your htaccess file

Code:
DirectoryIndex index.html index.php default.html default.php
 
i thought there was something about google not liking it when people did this?

Sure I read it on here a couple of months or so ago.
 
I will be actually having folders in the site directory. SO I don't think any needf for that to be in the code your produced> there will be over 20 pages - 4 main pages with a load of subpages for each of the 4 catagories. All of these will be in the relevant folders.

Just need some assistance to create some code that hides the .html & .php file extensions.

http://www.generateit.net/mod-rewrite/
 
i thought there was something about google not liking it when people did this?

Sure I read it on here a couple of months or so ago.

Source? So you're sauing Google would prefer domain.com/shoes.html inbstead of domain.com/shoes ?????

As an example, google seems to have indexed all of blogs pages that uses wordpress and a domain.com/33/article-title-here-jdsfjds format for urls
 
Last edited:
Back
Top Bottom