I am trying to use mod_rewrite to change the appearance of my URL's. I am really lost in this and could use some help. First of all, is it possible to use mod_rewrite to alter the "front-end" of a URL and keep it the same internally? If so, how would I do the following:
I have
https://domain.com/live/page.php?id=x
with both "page" and "x" being variable, and would like the URL's to be shown as
https://domain.com/page
if possible, or if I need the id=x in there then it could be
https://domain.com/page/x/
but I don't know if I need to have that id somewhere in the URL.
Please help me as I know this is a common thing but I just can't figure it out!
Thanks!
EDIT: With the help of anubhava I got this working halfway. This time I put the code into my .htaccess for the /live/ directory not the root one. Now the pages change URL correctly, but I still need the server to load from the original so the new URL's are giving me a 404. Here is the code:
RewriteEngine on
RewriteOptions inherit
RewriteCond %{THE_REQUEST} \s/+live/([^.]+)\.php\?([^=]+)=([^\s&]+) [NC]
RewriteRule ^ /%1/%2/%3? [R=302,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/.]+)/([^/.]+)/([^/.]+)/?$ /live/$1.php?$2=$3 [L,QSA,NC]
EDIT:
Here are my current .htaccess files
root:
RewriteEngine on
RewriteOptions inherit
RewriteCond %{HTTP_HOST} ^bidwaffle\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.bidwaffle\.com$
RewriteRule ^/?$ "https\:\/\/bidwaffle\.com\/live" [R=301,L]
and in root\live\:
# secure htaccess file
<Files .htaccess>
order allow,deny
deny from all
</Files>
# disable directory browsing
Options All -Indexes
# disable access to logs/template files
<Files ~ "\.(log|tpl)$">
order allow,deny
deny from all
</files>
RewriteCond %{THE_REQUEST} \s/+live/([^.]+)\.php\?([^=]+)=([^\s&]+) [NC]
RewriteRule ^ /%1/%2/%3? [R=302,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/.]+)/([^/.]+)/([^/.]+)/?$ /live/$1.php?$2=$3 [L,QSA,NC]
The URL changes properly but doesn't load properly (silent loading of the real URL). Right now I see the issue of the second part where it may not even see this request because the /live/ is no longer in the "pretty URL" so the /live/.htaccess might not be called. I tried putting that part into the root/.htaccess and it did the same weird thing with appending the referring page instead of %3