Reputation: 156
I would like to rewrite the URL from
https://www.example.com/index.php?page=SOMEPAGE&user=SOMEUSER
to
https://www.example.com/settings/user/SOMEUSER
where settings
is the page parameter from the URL. My Solution was:
RewriteEngine on
RewriteRule ^([-0-9a-zA-Z]+)/user/([-0-9a-zA-Z]+)$ index.php?page=$1&user=$2 [QSA,L]
The problem is, that all files respond with a 404 error code, because the browser seems to think that /settings/user
are actual folders on the server. How can I achieve that the actual URL path stays the same?
Upvotes: 1
Views: 56
Reputation: 45829
The problem would seem to be that you are using relative URLs to your resources. If you are changing the path depth of your URLs then you need to ensure you are using either root-relative (starting with a slash) or absolute (with a scheme + hostname) URLs throughout.
See my answer on the following question on the Webmasters SE site for more information:
because the browser seems to think that /settings/user are actual folders on the server.
No, the browser sees that as the URL-path. It IS the URL-path as seen in the browser. Any relative client-side URLs are going to be relative to this URL-path. The browser has non concept of what are server-side folders, it only deals with URLs.
How can I achieve that the actual URL path stays the same?
You are changing the URL-path in the browser, so the only way round this is to make your URLs non-relative.
Upvotes: 1