How can I exclude individual file types from URL forwarding with htaccess

fschneider

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.

RavinderSingh13

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.

edited at
0

Comments

0 comments
Login to comment

Related

How can I filter URL in htaccess file?

How can I stage individual lines from a deleted file in Git?

How can I exclude a particular file from test coverage analysis?

How can I exclude a file from deploy in gcloud?

How can I use the .htaccess file to rewrite URL's for a subdirectory?

how can I exclude collections when I get types from an assembly c#

.htaccess, how can I remove pattern from url?

how can i remove user folder from url using htaccess

How can I use scp to aquire a file from a server via a bastion with ssh forwarding?

How can I stop Files from oversimplifying file types?

How to exclude .php file from .htaccess redirect(rewriteRule)?

How can I access an individual element from JSON file via Angular4 HTTP Get?

How can I exclude $(this) from a jQuery selector?

How can I exclude the 10 from the output?

How can I redirect url's with htaccess?

htaccess exclude multiple url from Basic Auth

exclude url from htaccess redirect 301

How can I redirect .htaccess file to 404?

How can I combine several individual .ico files into a single file?

How can I exclude source file metadata from output when compiling?

In Yii2, how can I exclude layout from rendering in a view file?

How can I exclude files from indexing but include them in .war file?

How can I configure Polymer-cli build to exclude some file-path from being minified?

Android - How can I read a text file from a url?

How can I download a .exe file from a given URL?

How can I get Javascript Source(js file) from url?

How can I download a file from a URL and save it in Rails?

How can i submit a form with a file from URL programmatically

How can I save a JPEG from a URL to a file in angularjs(ionic)?