lundi 26 novembre 2018

How do you rewrite a URL with a query in a subdirectory using .htaccess

I'm building a website (no frameworks) and I have a .htaccess file in my root with working rewrite engine. I've been searching far and wide for a solution for my problem but nothing seems to work.

I'd like my site url to be displayed as: mysite.com/profile/profilename and for it to be rewritten to: mysite.com/profile.php?name=profilename so to give the illusion of there being another subdirectory when there isn't.

I've done a tonne of research and this seems to be the most logical to me but it doesn't seem to work:

DirectoryIndex index.php
RewriteEngine On
RewriteRule ^profile/(.*)$ profile.php?name=$1 [L]

(index.php is the home page to the site). When I try this, it doesn't come up with a 404, it comes up with the profile page, but without styling, it can't access the javascript I have in the root directory folder and the query didn't execute properly.

I have some simpler rewrites already active on the site so the rewrite engine is definitely on, but this more complicated style doesn't seem to work. Is it even possible to do this? And if so, what am I doing wrong?




Aucun commentaire:

Enregistrer un commentaire