Jump to content

mod_rewrite directory list?


Recommended Posts

Is it possible to use mod_rewrite totally rewrite URLS that exist in the same folder?

so:

folder/index.php?id=110 comes out as: folder/education.php

 

and

folder/index.php?id=120 comes out as: folder/research.php

 

Im assuming you would have to have a list in the .htacess file that references each file name, or is that rubbish? or could I use data from a mysql db to populate the name?

 

So:

folder/index.php?id=110 reads the title 'education' from the row in question and then fills that in as folder/education.php

Link to comment
Share on other sites

Ive had a go following some tutorials but I cant seem to get the url rewrite to work,

can anyone have a quick look and help identify where ive gone wrong?:

 

RewriteEngine on

RewriteRule ^/?whatwedo\index.html$ index.php?id=100 [L]

RewriteRule ^/?whatwedo\education.html$ whatwedo/index.php?id=110 [L]

RewriteRule ^/?whatwedo\research.html$ whatwedo/index.php?id=120 [L]

RewriteRule ^/?whatwedo\grants_awards.html$ whatwedo/index.php?id=130 [L]

RewriteRule ^/?whatwedo\national_societies.html$ whatwedo/index.php?id=140 [L]

RewriteRule ^/?whatwedo\newsletter.html$ whatwedo/index.php?id=150 [L]

RewriteRule ^/?whatwedo\news.html$ whatwedo/index.php?id=160 [L]

RewriteRule ^/?whatwedo\events.html$ whatwedo/index.php?id=170 [L]

 

 

Thank you very much,

 

Link to comment
Share on other sites

Try this :

 

Options +FollowSymLinks

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^whatwedo\/index\.html$ /index.php?id=100 [NC,L]
RewriteRule ^whatwedo\/education\.html$ /index.php?id=110 [NC,L]
...
</IfModule>

 

The first / is always present in all URL and remove before rewriterule, don't include it in your regular expression. You need to escape both / (slash) and . (dot). And don't use that \ (backslash) as a separator for domainname/directory/file it's always this / (slash).  And i added [NC] in the flag, mean no case (case insensitive).

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.