Jump to content

Recommended Posts

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

 

Link to comment
https://forums.phpfreaks.com/topic/317270-htaccess-error/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/317270-htaccess-error/#findComment-1611715
Share on other sites

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 ??

Link to comment
https://forums.phpfreaks.com/topic/317270-htaccess-error/#findComment-1611721
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/317270-htaccess-error/#findComment-1611722
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/317270-htaccess-error/#findComment-1611723
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/317270-htaccess-error/#findComment-1611730
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.