I have a couple of questions regarding how .htaccess works.
1 Does htaccess affect SRC linked files. for example, would a rewrite rule that redirects all rquests to /index.php prevent also redirect the theme/css/style.css in the style tag of index.php to /inxded.php, or does the redirection only affect the URL entered in the address bar of the browser?
I was trying to write a set of conditions that would do the following:
• Redirect requests to index.php if:
the requested url is a directory AND does is NOT named ‘engine’ OR ‘content’
the requested url is a directory AND does not exist
the requested url is a file AND does not exist
the requested url is a file that exists and has the suffix ‘.php’ OR ‘.html’ OR ‘.htm’ OR ‘.asp’
in short, any url except ‘/engine’ would cause a rewrite.
I came up with this… but it fails to rewrite anything
RewriteEngine On #redirect non existent pages
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d #redirect all directory request EXCEPT ‘engineFolder’
RewriteCond %{REQUEST_URI} !^/engineFolder [NC,OR] #redirect all file request that end in ‘.php’,‘.html’,‘.htm’,‘.asp’
RewriteCond %{REQUEST_URI} /[\w]+.(php|html|htm|asp)$ [NC]
RewriteRule .* index.php [L]
RewriteRule only changes what is served for a URL entered in the browser, it does not modify your HTML in any way whatsoever
Not really sure what you’re after. First you say “‘engine’ OR ‘content’”, then “in short, any url except ‘/engine’ would cause a rewrite.” and the code you’ve provided is for “engineFolder”. Which is it?
Also, a file cannot exist and not exist at the same time, bullets 3 and 4 are contradicting each other. Sounds like you maybe want 4 separate RewriteRules instead of one? All RewriteCond’s are combined with AND, so now it’s a list of 4 conditions that all need to be met before the RewriteRule fires.
It depends how the redirect is set. If its domain specific. All the path will redirect.
IF its file specific. Then it will not redirect in case of other files hosting on the server.
I was asking because, i have come close to making the redirect work like i would like, but when it goes to the page none of the styles of .js is present ; I figured it could a problem with the links in the header which are relative.
I mean the directory with the htacess file contains 4 items by default: index.php, engine, themes , and content. unless the user is trying going to the engine directory, the user should be redirected to the index.php file.
2-a) Incidentally, my original attempt only contains the conditions:
RewriteCond %{REQUEST_URI} !^/engineFolder [NC,OR] #redirect all file request that end in ‘.php’,’.html’,’.htm’,’.asp’
RewriteCond %{REQUEST_URI} /[\w]+.(php|html|htm|asp)$ [NC]
I though the spec stated that [OR] joined the next conditions an OR. ( else , how would you go about writing OR condition)
but that didn’t cause any redirects at all. Perhaps I have a typo in my logic? I am unfamiliar to how the regex for htacess behaves.
the decision tree I would like to follow is:
rewrite any directory requests(to existing or non existing directories) to index.php UNLESS it’s the ‘/engine’ directory
if the URL is a file (without query string) ends in .php,.asp, .html, or .htm rewrite to index.php
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/engine [NC,OR]
#redirect all file request that end in ‘.php’,’.html’,’.htm’,’.asp’
RewriteCond %{REQUEST_URI} \.(php|html|htm|asp)$ [NC]
RewriteRule ^ /index.php
It ALMOST worked. The one thing what went wrong with this solution, the thing thats burning my noodle, is that the stylesheets and scripts are still not linking (so it does navigate to index.php, which then runs an include of the expected page, but no CSS is loaded )
I was fiddling with this less than graceful solution: