Mod Rewrite Query

No one?

I've googled it, but seems to only be solutions for number - number, or text - text, not one to the other, if that makes sense? :confused:
 
It's certainly possible, but you need to have some kind of mapping between which /pagename relates to which /index.php?pageid=x uri. Does this need to be dynamic or just for this one instance? Do you have a way to change index.php so that it can select based on 'pagename' rather than ID?

For example:

  • Rewrite /pagename to /index.php?name=pagename and have your index.php script select the correct content
  • Have a URL like /1/pagename rewrite to /index.php?pageid=1
  • Have separate explicit rewrite rules for every /pagename to /index.php?pageid=x mapping (cf. RewriteMap)

Need further information to be able to suggest the best rewrite rule.
 
Yes it needs to be dynamic as pages will be added/deleted - I could probably amend it so that it uses the page name rather than the page id.
 
To rewrite /pagename to /index.php?page=pagename:
Code:
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.+) - [PT,L]

RewriteRule ^([^/]+)/? index.php?page=$1 [L]

The set of Rewrite Conditions (RewriteCond) ensure that if a real file or directory exists with the requested name, it won't get rewritten by the later rule e.g. your images or css directory. The last rule is the one which rewrites anything like /pagename to /index.php?page=pagename with an optional trailing slash (/?).
 
Back
Top Bottom