user3719477
user3719477

Reputation: 110

Rewrite URL but keep external files

I've been making a web app with PHP but the problem is that when I try to rewrite:

http://example.com/user.php?username=user121

to:

http://example.com/user/user121

with HTACCESS, it loses all external files and only keeps the page's HTML. Please help me out?

My current Rewrite Rule:

RewriteRule users/([^/]+) user.php?username=$1 [NC,L]

Upvotes: 1

Views: 61

Answers (1)

anubhava
anubhava

Reputation: 785246

Use any one of these solutions.

Solution 1: use absolute path in your css, js, images files rather than a relative one. Which means you have to make sure path of these files start either with http:// or a slash /.

Solution 2: Try adding this in your page's HTML header:

<base href="/" />

Solution 3: Add this rule in your .htaccess:

RewriteRule users/(.+?\.(?:jpe?g|gif|bmp|png|tiff|css|js))$ /$1 [NC,L,R=301]

Upvotes: 1

Related Questions