Apache RewriteRule

Can someone pls help with this?

I need to att a path to the request string

e.g.

localhost/site.se/start.php needs to be
localhost/site.se/html/start.php,

localhost/site.se/kontakt.php needs to be
localhost/site.se/html/kontakt.php

and so on.

Tried something like: RewriteRule ^site[.]se/$(.*) site[.]se/html/$1
Didn’t work

First off, you need to start with RewriteEngine on. Without that, the rule(s) will not work.

Second, for the RewriteRule itself, you must not include the domain in the rule, only the path.

Also, the $ sign is off in your rule, it should be in the very last position after (.*)

Can’t figure it out :expressionless:

This tutorial should help.

RewriteEngine On
RewriteRule ^(.*)$ html/pages/$1

Done some reading now and the above should work, but it doesn’t. “internal error” when I use the variable “$1” :S

Anyone?

Did you check the server setup in @Gandalf’s tutorial link?

It’s loaded.
The rewrite works if I dont use the variable, but I need it to work with the var

“Request exceeded the limit of 10 internal redirects due to probable configuration error. Use ‘LimitInternalRecursion’ to increase the limit if necessary. Use ‘LogLevel debug’ to get a backtrace”

Since your rule rewrites everything it will get in a loop.

First it will rewrite foo to html/pages/foo, then it will rewrite html/pages/foo to html/pages/html/pages/foo, etc etc, until Apache is fed up and stops.

What you want is add something to prevent the redirect when the path already starts with html/pages.

Something like

RewriteEngine On
RewriteCond %{REQUEST_URI} !^/html/pages
RewriteRule ^(.*)$ html/pages/$1 [L]
2 Likes

Thank you. But why doesn’t it behave the same way when I remove the var? E.g.

RewriteEngine On
RewriteRule ^(.*)$ html/pages/contact.php

Work without problem

Because then it changes html/pages/contact.php to html/pages/contact.php, which isn’t actually a change. And since no change happens, the rewrites won’t be applied a second time.

Basically Apache keeps applying the RewriteRules until

  1. The result is the same as what went in; or
  2. It’s done 10 rounds of rewrites and things still keep changing

The second one is to prevent infinite loops

1 Like

Thank you :slight_smile:

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.