0

I'd like to know, how I can use php's function mode_rewrite correctly. I'm currently developing with xampp. I've activated LoadModule rewrite_module modules/mod_rewrite.so in the httpd.conf file. Also I edited following lines:

<Directory />
    Options FollowSymLinks
    AllowOverride All
    Order deny,allow
    Deny from all
</Directory>

In my .htaccess file, I've following code:

RewriteEngine On
RewriteRule ^([^/]*)\.html$ /?m=$1 [L]

So it should change ?m=start to ?start.html. When I now open localhost/page/start.html, it only shows me "It works". But why doesn't it show me the content from localhost/page/?m=start ?

A further question would be, how do I change the rewrite rule, that I could access localhost/page/?m=start&set=update through localhost/page/start/update.html?

Thank you for an answer!

The Archetypal Paul
  • 41,321
  • 20
  • 104
  • 134
damian
  • 5,314
  • 5
  • 34
  • 63

1 Answers1

1

You are using the absolute path / in your substitution. So when using this rule in the .htaccess file in /page/ a request of /page/start.html will actually be rewritten to /?m=start and not /page/?m=start.

Try a relative path instead:

RewriteRule ^([^/]*)\.html$ ./?m=$1 [L]
Gumbo
  • 643,351
  • 109
  • 780
  • 844
  • Wow, very fast response :) Thanks, it's working now. Could you also tell me, how I can solve my second problem? I've for example this localhost/page/?m=kontakt. When I've sent the form on this page, the url looks like localhost/page/?m=kontakt&set=update. How must the rewrite rule look like? – damian Dec 03 '10 at 16:26
  • @Damian Frizzi: Oh, didn’t see that. Well, in that case you need to use a `RewriteCond` and look at the value of `%{QUERY_STRING}`. But to avoid mutual recursion, you also need to look at `%{THE_REQUEST}` or check for a response status code. That’s a little more complicated. So in case you are using not just static files but a programming language, you should better use that programming language to do that redirect. – Gumbo Dec 03 '10 at 16:29
  • Puh, that's a little bit hard to understand for me. I've never worked with this before. Where do I get the value of %{QUERY_STRING} and %{THE_REQUEST}? I'm using php, how can I use this language to do a redirect? – damian Dec 03 '10 at 16:37
  • @Damian Frizzi: Take a look at these answers: http://stackoverflow.com/questions/1217981/htaccess-rewrite-issue/1219119#1219119, http://stackoverflow.com/questions/4054738/rewriterule-loop-redirection/4054803#4054803, http://stackoverflow.com/questions/2938699/rewrite-url-to-index-php-but-avoid-index-php-in-the-url/2938734#2938734 and http://stackoverflow.com/questions/2852386/mod-rewrite-handling-two-get-variables/2865531#2865531 – Gumbo Dec 03 '10 at 16:50