Warm tip: This article is reproduced from stackoverflow.com, please click
.htaccess php

Is Absolute Paths the only solution for htaccess URL Rewrite Issues?

发布于 2020-04-03 23:40:58

So im trying to do something simple, just want to change the urls like for example:

website.com/user?slug=usernameexample to website.com/user/usernameexample and I used the code below:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/?user/([^/d]+)/?$ user.php?slug=$1 [L,QSA]

Seems simple but for my surprise this is a little nightmare because in the url website.com/user/usernameexample all files like css/js and others will not work because will try to open inside the directory "user" And thats not all... Also all links and files will try to the same, so for example login.php will also try to open inside the "user" folder that does not exist...

After reading many stackoverflow answers seems that the most common answer is "Absolute Paths" or <base href="http://www.example.com/" />... However The "base href" answer don't really works properly because that brings other issues... So seems that "Absolute Paths" are the only viable answer?

I wonder If there is another solution... I did tried some small htaccess changes but they did not worked with me...

Questioner
ramenknight
Viewed
70
ramenknight 2020-01-31 20:29

Yes, Absolute Paths are the only viable answer.