4

I want to create flat links for my website. The .htaccess code is following:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^([0-9A-Za-z]+)?$ /index.php?page=$1 [L]
    RewriteRule ^([0-9A-Za-z]+)/?$ /index.php?page=$1 [L]
</IfModule>`

Now my website is working which can be seen through print_r($_GET) and getting all the values.

My website has a code like this: <img src="images/icons/image.png" />, where the image resides on path: /images/icons/up.png.

Now I can visit my website as: http://somedomain.com/home and everything works fine. But when I put: http://somedomain.com/home/, it gets stuck.

The image gets a path like this for the browser: http://somedomain.com/home/images/icons/image.png which is not available and it should be: http://somedomain.com/images/icons/image.png.

How to solve this?

It would helpful if there is any solution by modifying the .htaccess as I want to use relative paths for all links and not full path.


Thanks to Ben Clifford for your help. According to him if I redirect the second rule one to the format like the first one and not over index.php. Then it should work.

halfer
  • 19,824
  • 17
  • 99
  • 186
Sukanta Paul
  • 784
  • 3
  • 19
  • 36

1 Answers1

1

You could change that second rewrite rule to redirect the user to the non-/ version of the path, rather than to index.php; then when that redirected page is loaded it would hit the first rule, with the correct base path.

The issue is that the image name replaces everything after the last / in the URL: when you say somedomain.com/home then the image filename is appended to somedomain.com/ but in the second case, the final / is after the home. Using a rewrite rule to prune this / off would fix that, i think.

Ben Clifford
  • 1,398
  • 1
  • 12
  • 23