views:

41

answers:

2
+2  Q: 

mod_rewrite Probs

Hi Guys,

I am quite new to PHP and just getting started with mod_rewrite. I know the basic lingo but come stuck when I want to simply refer to the route directory

i.e. this is not probs

RewriteRule ^settings/$ settings.php [QSA,L]

But how to for example make:

RewriteRule ^page/(.*)$ index.php?Page=$1 [QSA,L]

which generates /page/[page-name]

Just become

/[page-name]

?

+1  A: 

This should do it:

RewriteRule ^(.*/)$ index.php?Page=$1 [QSA,L]

However, you should place that rewrite rule after all the other specific rewrite rules you have, otherwise all requests will be redirected to index.php?Page=....

Alix Axel
hey thanks - yeah i tried that = i am using http://vanillaforums.org/addon/60/page-manager/50/50/ - but it seems when i do that none of my styles load ?
Thomas
Try my updated version. URLs need a ending dash though.
Alix Axel
hmm thanks again but now that gives me "not found" i.e. for either /page/[page-name] or /[page-name] ?
Thomas
"URLs need a ending dash though."
Alix Axel
"URLs need a ending dash though." :) hey thanks again - not sure what you mean ? ^(.*/)$ index.php?Page=$1- [QSA,L] or ?
Thomas
It means it'll only work if you access pages like this: `[page-name]/`.
Alix Axel
ahhh thanks - its working :)
Thomas
+2  A: 

Maybe I didn't understand you but it seems that you need such .htaccess file to solve your problem.

<IfModule mod_rewrite.c>
  RewriteEngine On

  RewriteBase /

  # Ignore valid files
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d    

  RewriteRule ^(.*)$ index.php?Page=$1 [QSA,L]
</IfModule>
Darmen
hey thanks for the response - it seems when i add this none of my styles load ?
Thomas
sorry, my bad - see updated answer
Darmen
hey darren - thanks again. tried this but again didn't seem to work ? i.e. just redirects back to index.php ?
Thomas
The `RewriteBase` is probably unnecessary.
outis