i've written this rewrite rule for my AngularJs application that use html5 routing.
The rewrite url is this:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^.*\.(jpg|css|js|gif|png|html|woff)$
RewriteRule ^ index.html [L]
I want that all the URL that contains path /old/ and with path /images/ aren't rewritten!
Someone can help me i tried to add rewrite condition like this :
RewriteCond %{REQUEST_URI} !^/old/
But it doesn't work!
Regards, Lorenzo
UPDATE
If you're using AngularJS with routing use target="_self" on <a>
element that has link in the same domain but aren't under the angular routing!
A rewrite is a server-side operation that occurs before a web server has fully processed a request. A rewrite is not visible to website visitors, since the URL displayed in the browser does not change.
$1 represents the match from the first set of parentheses in the RewriteRule regex, not in the RewriteCond regex.
htaccess rewrite rules can be used to direct requests for one subdirectory to a different location, such as an alternative subdirectory or even the domain root. In this example, requests to http://mydomain.com/folder1/ will be automatically redirected to http://mydomain.com/folder2/.
Your third RewriteCond
is useless since you're already checking for existing files in first condition.
Also, if you're in a subdirectory (like /old/
or something, you should add a RewriteBase
or a leading slash to your index.html
. Otherwise it will look in current directory (404 error probably).
You can replace your code by this one
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/(old|images)/ [NC]
RewriteRule . /index.html [L]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With