geatzo Posted September 9, 2023 Share Posted September 9, 2023 So im trying to make my url pretty so instead of profile.php?id=1 it will show profile/1 RewriteEngine on RewriteCond %{HTTP_HOST} ^geatzo.com$ [NC,OR] RewriteCond %{HTTP_HOST} ^www.geatzo.com$ RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d # # Reroute SEO-friendly profiles to profile.php # eg. /profile/123 to /profile.php?profile=123 # RewriteRule ^profile/([0-9]+)$ profile.php?profile=$1 [L] I have wrote this which works but for some reason now the site works but when i visit the new url its looking for all my images in the profile folder and also all the links are being pointed to /profile/ https://prnt.sc/1pdYhf8aR448 Quote Link to comment Share on other sites More sharing options...
requinix Posted September 9, 2023 Share Posted September 9, 2023 When you use URLs like "sub.png", for images or CSS or basically anything at all, the browser will look them up according to the "directory" in the page's URL. Before the rewriting, your URL was like /profile.php?profile=123 so "sub.png" would mean /sub.png. After the rewriting, your URL is now /profile/123 so "sub.png" means /profile/sub.png. Use absolute URLs for these sorts of things: that's with a leading slash, and starting from the root of your website. As in "/sub.png", which will always mean /sub.png regardless of what page you're on. Quote Link to comment Share on other sites More sharing options...
geatzo Posted September 10, 2023 Author Share Posted September 10, 2023 10 hours ago, requinix said: When you use URLs like "sub.png", for images or CSS or basically anything at all, the browser will look them up according to the "directory" in the page's URL. Before the rewriting, your URL was like /profile.php?profile=123 so "sub.png" would mean /sub.png. After the rewriting, your URL is now /profile/123 so "sub.png" means /profile/sub.png. Use absolute URLs for these sorts of things: that's with a leading slash, and starting from the root of your website. As in "/sub.png", which will always mean /sub.png regardless of what page you're on. ive tried making a folder called profile and adding all the images into it which works but then all the links on the page changes to /profile/login.php etc ?? Quote Link to comment Share on other sites More sharing options...
requinix Posted September 10, 2023 Share Posted September 10, 2023 1 hour ago, geatzo said: ive tried making a folder called profile and adding all the images into it which works but then all the links on the page changes to /profile/login.php etc ?? So you tried doing something more difficult and awkward and it created more problems than it solved, right? Then don't do that. Quote Link to comment Share on other sites More sharing options...
geatzo Posted September 10, 2023 Author Share Posted September 10, 2023 2 hours ago, requinix said: So you tried doing something more difficult and awkward and it created more problems than it solved, right? Then don't do that. why the hate ? Im simply trying to make the url more pretty more than happy top make a new folder and move everything into it but this does not fix the linking issue. I guess i just need to set the root has the domain name instead of profile Quote Link to comment Share on other sites More sharing options...
maxxd Posted September 10, 2023 Share Posted September 10, 2023 requinix told you how to fix it and you didn't do that. You need to use absolute URLs in your image src attributes: <img src="this/is/wrong.png"> vs <img src="/this/is/right.png"> You don't need to create a new directory and move images into it, just update your source attributes. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.