0

I have these lines in my httpd.conf which make the all the url as a single parameter ('name') and when I type an name that doesen't exist index.php is loaded properly and a 404 message is shown. But the problem is that JavaScript, CSS and other assets are not loaded. How to load those files even if a dir/ file doesn't exists. ? I'm using relative paths. Thanks ;)

<Directory  "c:/Apache24/htdocs/public">
    <IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule ^(.+)$ index.php?name=$1 [QSA,L]
    </IfModule>
</Directory>
1
  • 1
    Add this in the <head> section of your page's HTML: <base href="/" /> so that every relative URL is resolved from that URL and not the current page's URL. Commented Feb 9, 2015 at 18:25

1 Answer 1

1

Generally, the FallbackResource directive is a cleaner and more performant way to achieve what you're trying to do here:

http://httpd.apache.org/docs/trunk/mod/mod_dir.html#fallbackresource

Instead of the mod_rewrite stuff, just write this:

FallbackResource index.php

Inside the PHP script you can then turn the PATH_INFO environment variable into whatever you're using to capture the name argument.

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

2 Comments

Can you explain me why this is faster and more performant than mod_rewrite? I did this in httpd.conf but now how can I get the name variable from the url via PATH_INFO if my url for ex. is sth like http://localhost/john ? Thanks @djc
I think this will treat all the url as non existent because name variable will be dynamic. and there will not be a file 'name.php'

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.