0

I am trying to rewrite URL from example.com/test.php?id=hd3j3 to example.com/id/hd3j3.
The problem is rewriting occurs and I am taken to the page but the css and js of the page doesn't load. Where am I going wrong?

.htaccess

RewriteBase /
RewriteEngine On
RewriteRule ^id/([A-Za-z0-9]+)$ test.php?id=$1 [L]
2

2 Answers 2

1

Your rewrite rule looks right for me.

Maybe your css gets loaded from a relative path and not absolute ?

<link href="css/layout.css">

The browser try to load from example.com/id/css/layout.css instead of example.com/css/layout.css

Sign up to request clarification or add additional context in comments.

5 Comments

So what do you actually suggest?
<link href="/css/layout.css">
Ok, that seems to do the work. But isn't there any other way so that I dont require to change the file paths?
You add a <base href="example.com"> in the <head> tag. So u dont need to change all file paths.
What about RewriteCond ?
0

Try to clear the cache and retry ! This usually works.Or set the root path correctly. If these won't work try this, If you want to use image tag and show to correctly images, use " />

1 Comment

Nopes, Cache clear and retrying didn't work. Absolute paths needs to be set. But I need a better way using htaccess. Or else I will need to sit and change paths for many files.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.