I have read ALOT of threads about htaccess rewriting but struggling to get anything to work as I need it to.
I am spinning my wheels here for a few hours.
I have two pages in my folder.
/proposal/index.php
/proposal/dl.php
So normal queries would look like this.
/proposal/?code=123abc
/proposal/dl.php?code=123abc.
But I want to send it to the user like this:
/proposal/123abc/
/proposal/dl/123abc/
Can someone help me with this?
TIA
NOTE
I did try the code below which works perfectly on index.php but has no effect on dl.php (if I add dl.php to the mix)
RewriteEngine On
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule . index.php [L]
2
Answers
In the end, this worked.
Now I am able to call the pages like this:
/proposal/123abc/
/proposal/dl/123abc/
All I did was add the line below to my original code.
The structure of my subdirectory is as follows:
/proposal/.htaccess
/proposal/index.php
/proposal/dl.php
Now I am able to provide nice URLs to the clients for these two files and call up their content using my parameter like:
/proposal/123abc
/proposal/dl/123abc
Which would be like this in a normal way
/proposal/index.php?code=123abc or /proposal/?code=123abc
/proposal/dl.php?code=123abc
This probably is the variant you are looking for. Both rules capture the actual argument embedded in the requested URL to re-use it in the internally rewritten request.
Yo may also want to add redirection rules to redirect clients using the "old" URLs:
For this it is a good idea to start out with a 302 redirection and only to change it to 301 when everything works as expected.
Both variants use relative paths so that the rules work in distributed configuration files somewhere deeper than the document root of your http server. I personally prefer to implement such rules in the real host configuration instead of using distributed configuration files ("htaccess") for various reasons.