What I've been trying to achieve is to get my .htaccess file to rewrite ALL URLS.
No matter what I do, however, I cannot get it ignore existing directories. And by that, I mean, act as if they don't exist.
For example, say I have the following file structure:
/
dir1
file1.php
dir2
file2.php
.htaccess
And suppose I want to redirect all traffic to dir1/file1.php?url=path
.
This never works for me if the path is an existing directory.
For example, if I navigate to url/path/stuff/dir2
, the "redirecting" works, but the URL in the address bar changes to url/path/stuff/dir2/?url=dir2
for some unfathomable reason.
Here is my .htaccess
:
Options -MultiViews
Options -Indexes
Options +FollowSymLinks
# so navigating to a url with a trailing slash won't cause problems
DirectorySlash Off
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ dir1/file1.php?url=$1 [QSA,L]
You (updated) .htaccess is saying: IF (it is not an existing file) THEN { rewrite the URL }. Seems like you want
RewriteEngine on
RewriteCond %{REQUEST_URI} !dir1/file1.php
RewriteRule ^(.*)$ dir1/file1.php?url=$1 [QSA,L]
In this case, the RewriteCond just prevents infinite looping. The RewriteRule gets applied once and only once. Rewrite module will keep cycling thru all the rules until a cycle does not result in a changed to the URI.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.