I am using mod rewrite to redirect all demands focusing on non-existent files/sites to index.php?url=*

This really is surely the most typical factor you need to do with mod_rewrite yet I've got a problem:

Naturally, when the page url is "mydomain.com/blog/view/1", the browser will search for images, stylesheets and relative links within the "virtual" directory "mydomain.com/blog/view/".

Problem 1:

  • Is applying the bottom tag the very best solution? I observe that no PHP frameworks available make use of the base tag, though.

  • I am presently getting a regex replace all of the relative links to suggest right path before output. Is the fact that "okay"?

Problem 2:

It's possible the server does not support mod_rewrite. However, all public documents like images, stylesheets and also the demands collector index.php are situated within the directory /myapp/public. Normally mod_rewrite points all request to /public therefore it appears as though public was really the main directory too all customers.

If however there's no mod_rewrite, Then i need to point the customers to /public in the root directory having a header() call. Which means, however that links are damaged again because all of a sudden all images, etc. need to be known as via /public/myimage.jpg

Information: When there's no mod_rewrite the above mentioned request would seem like this: mydomain.com/public/index.php/blog/view/1

  • What will be the best solutions for problems?

Edit/Additional question:

It is possible to method to make /public/ the bottom dir using plain htaccess code?

Write the application in a way it does not need mod_rewrite to operate (at the expense of getting "ugly" web addresses). Progressively enhance it with mod_rewrite to offer the preferred result. This most likely implies that you will need to store some base path config info inside your application.

I do not understand these complaints whatsoever. Yes, this really is surely the most typical factor you need to do with mod_rewrite, yet with 2 conditions:

RewriteCond  %{REQUEST_FILENAME} !-f
RewriteCond  %{REQUEST_FILENAME} !-d

So, nothing hurt your overall images.

Why don't you to make use of just absolute path, e.g. /myapp/public/myimage.jpg, so, no virtual directory will hurt image path?

how about path info? You could utilize it without mod_rewrite


echo $_SERVER["PATH_INFO"]; // outputs /path/to/another/file.jpg

Anyways, if you wish to determine if mod_rewrite is based on your server :

echo "mod_rewrite : ".(!empty($_SERVER["REDIRECT_URL"])?"supported":"not supported");

Then you definitely ll determine if mod_rewrite may be the solution or possibly path_info is much more perfect for you, you can make support functions that may search for both too.