php - Which htaccess rules would allow for navigating a webapp as specified?
one text
I have a Web App stored in a directory htdocs/webapp
.
The PHP code is in an extra subdirectory on its own: htdocs/webapp/php
which is where the entry point for my web app (index.php
) is.
The .htaccess
inside htdocs/webapp/php
has the following content, especially the RewriteRule
s:
RewriteEngine On
RewriteBase /app/php
# page
RewriteRule ^([a-zA-Z0-9_-]+)$ index.php?page=$1&subpage=home [QSA]
# page+subpage
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)$ index.php?page=$1&subpage=$2 [QSA]
Now, my index.php
contain links and stuff.
I would like to write links so that, e.g. going to the login
page would read in the HTML something like:
<base href="php/"/>
...
<a href="login">Login</a>
With my current setup, I get the above link to point to webapp/php/php/login
instead of webapp/php/login
.
How could I fix this using a .htaccess
directive? I suspect it has to do with the RewriteBase
rule, but omitting it produces the same behavior and providing the absolute path:
RewriteBase /C:/Bitnami/wampstack-7.4.13-0/apache2/htdocs/webapp/php
will trigger a 403 error.
Note that I need
<base href="php/"/>
because otherwise trying following different page will cause the links to "accumulate" pages, e.g.
<a href="page2">Login</a>
will go to webapp/php/page1/page2
if the link is followed from page1
, but I would like to get to webapp/php/page2
.