I want to redirect every url entered in the Browser to the index.php.
This also works with my Code. For Example:
url.com/test1/test2/test3
url.com/test1/test2
url.com/test1
The CSS, images and JS files are also always forwarded. I now have to exclude files with certain extensions (css, js, jpg, png, pdf) from the redirection.
My code in the htaccess file:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?path=$1 [NC,L,QSA]
My Code in the Index file where i import the css-file:
<link href="css/bootstrap.min.css" rel="stylesheet">
If I enter "url.com/test" the integration of my css file works. When I enter "url.com/test/test2" the stylesheet file does not load.
Firstly make sure to place your htaccess rules file into root directory. You may need to use base tag to fix your js and other relative resources. If you are linking js files using a relative path then the file will obviously get a 404 because its looking for URL path. for example if the URL path is /file/ instead of file.html then your relative resources are loading from /file/ which is not a directory but rewritten html file. To fix this make your links absolute or use base tag. In the header of your webpage add this <base href="/">
so that your relative links can load from the correct location.
Please make sure to clear your browser cache before testing your URLs.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments