I am trying to adjust my htacess file to skip the rewrite rule if the file or directory exists, but when the file exists, it changes the URL to something different. I don't know why this is happening. Here is my htaccess file:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f [OR]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^project/([^/\.]+)/?$ index.php?view=project&project=$1 [L]
RewriteRule ^for/content/ag index.php?view=opening§ion=ag [L]
RewriteRule ^for/content/bus index.php?view=opening§ion=bus [L]
RewriteRule ^for/content/fcs index.php?view=opening§ion=fcs [L]
RewriteRule ^for/content/market index.php?view=opening§ion=market [L]
RewriteRule ^for/content/trade index.php?view=opening§ion=trade [L]
RewriteRule ^for/content/teched index.php?view=opening§ion=teched [L]
RewriteRule ^for/content/([^/\.]+)/?$ index.php?view=content_area§ion=$1 [L]
The directory /project/nti exists, with an index.php file. When the address mywebsite.com/folder/project/nti is entered, it changes to mywebsite.com/folder/project/nti/?view=project&project=nti. I am applying this on a test server where the sample site is in a subfolder, but when implemented, it will be in the root web server folder.
Thanks for any help!
RewriteCond %{REQUEST_FILENAME} !-f. RewriteCond %{REQUEST_FILENAME} !-d. … means that if the file with the specified name in the browser doesn't exist, or the directory in the browser doesn't exist then procede to the rewrite rule below.
The <IfModule mod_rewrite. c>... </IfModule> block ensures that everything contained within that block is taken only into account if the mod_rewrite module is loaded. Otherwise you will either face a server error or all requests for URL rewriting will be ignored.
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/.
NC = nocase means regardless of the case of the incoming referrer traffic match with the given pattern. See Apache [NC|nocase] flag.
Remove extra [OR]
and have your code like this:
# If the request is not for a valid directory
RewriteCond %{REQUEST_FILENAME} !-d
# If the request is not for a valid file
RewriteCond %{REQUEST_FILENAME} !-f
# If the request is not for a valid link
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^project/([^/.]+)/?$ index.php?view=project&project=$1 [L,NC,QSA]
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