I already searched for the answer in other questions and tried a few solutions with no luck:
In the root of my website I use the following code in .htaccess and it works fine:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [L,QSA]
But now I need to define that when I'm in the /admin directory it has to act normal.
Because when for example I link a stylesheet in a file in /admin, I have to define the src as "/admin/something.css" because else it will look for domain.com/css/something.css
Can someone tell me what to do?
Added:
RewriteRule ^admin - [L,NC]
Before anything else.
The - means do nothing.
The L means this should be last rule; ignore everything following.
The NC means no-case (so "ADMIN" is also matched).
Source
Related
I've got an install of concrete5 living in my site root - the problem is that the C5 file structure is pretty varied, and it's getting mixed in with my subdirs and subdomains. I can't tell what's my code and what's C5, I hate it.
My solution is to move everything to a /_concrete/ folder - but since my domain has to point to the root, I can't use the files here.
Enter .htaccess: I need to write a script to redirect any instance of www.domain.com (ignore subdomains) to www.domain.com/_concrete/ - but not a transparent 301, just an alias. To clarify: www.domain.com/page/ and www.domain.com/_concrete/page/ should display the same thing. www.domain.com/page/ should NOT change it's URL to www.domain.com/_concrete/page/.
I've adapted this from a similar script I use elsewhere:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /_concrete/$1 [L,QSA]
But this only causes a server error. I hope I'm close - can anyone point me in the right direction?
You're telling the server to check if the value is not a filename, but you're not having it ignore the _concrete directory itself (which would also match your script and create a loop).
This might get you closer to what you're trying to do.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !^_concrete
RewriteRule ^(.*)$ _concrete/$1 [L,QSA]
Additionally you might want to have it ignore directories that exist as well. At which point _concrete would no longer be matched because it exists.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ _concrete/$1 [L,QSA]
I get how to remove index.php from CI urls overall. The following works fine:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /crm/v2/index.php?/$1 [L]
However, it interfers with other code on the live site. This new CI version i'm adding is in a subdir named v2. Thus the layout is something like:
-originalDir
--v2
-otherDirs
-.htaccess
-etc...
So in essence urls come out something like:
// Original page
https://www.site.com/originalDir/somepage.htm
// And this exist too
https://www.site.com/originalDir/index.php
// My new stuff
https://www.site.com/originalDir/v2/index.php/controller/etc...
// Desired effect withOUT affecting the original sites index.php page
// aka, the below is what i WANT but NOT getting!
https://www.site.com/originalDir/v2/controller/etc...
I can code in a lot of languages, but never a lot of experience with these htaccess rewrites. Any ideas on how to make it rewrite index.php for ONLY the codeigniter sub-directory? I've tried a few things that seem to work locally, but not on the live server. Not sure the exact structure of rewrite code.
Assuming you want to only rewrite rules in the CI directory, and not point any URLs outside of that directory to it...
Change your RewriteRule to match only URI's that start with your CI directory.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^crm/v2/(.*)$ /crm/v2/index.php?/$1 [L]
Alternatively, you can put an .htaccess file in your /crm/v2 directory, and specify a RewriteBase.
RewriteEngine on
RewriteBase /crm/v2/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
Have you tried using RewriteBase?
RewriteEngine On
RewriteBase /crm/v2
RewriteRule ^(.+)$ index.php?/$1 [L]
I have not tested this specifically with your information but this is from a template that I use for some of my projects.
Here is the documentation for RewriteBase: http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewritebase
I hope this helps!
The following .htaccess file works perfectly on my local server.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} \.cssc
RewriteRule . style.php [L]
RewriteRule ^admin\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . admin.php [L]
I am doing some work for a client and he is using 1and1.com. I do not know anything about his account or what package he has.
All files are rewritten to admin.php (unless they actually exist). The problem is, I am getting a 404.
I know it's reading the .htaccess file because:
I can put garbage in the file and get a 500 error.
If I do a general rewrite (all pages go to admin.php), it works.
Also, it seems that 1and1 does it's own rewriting. If I go to: http://somewhere/afile, it will include afile.js even though I am not requesting the .js.It is super strange.
Does anyone have any experience with this? Or any insight?
To add some information..
1and1 seem to have some sort of default rewriting already in place that can interfere with your own rules - for example:
RewriteRule ^product$ /product.php [L]
It gave a 404 for this, and also for any other rewrite rule that matched a pre-existing .php file in my root folder.
2 things that 'fixed' it:
Change rewrite text to no longer match filename:
RewriteRule ^productz$ /product.php [L]
Or, change filename:
RewriteRule ^product$ /product_.php [L]
Both work - both very annoying.
The answer was simply "Do not nest .htaccess files". I had one in a sub folder.
I have following rewrite rules for a website:
RewriteEngine On
# Stop reading config files
RewriteCond %{REQUEST_FILENAME} .*/web.config$ [NC,OR]
RewriteCond %{REQUEST_FILENAME} .*/\.htaccess$ [NC]
RewriteRule ^(.+)$ - [F]
# Rewrite to url
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !^(/bilder_losning/|/bilder/|/gfx/|/js/|/css/|/doc/).*
RewriteRule ^(.+)$ index.cfm?smartLinkKey=%{REQUEST_URI} [L]
Now I have to exclude a script including its eventually querystrings from the above rules, so that I can access and execute it on the normal way, at the moment the whole url is being ignored and forwarded to the index page.
I need to have access to the script shoplink.cfm in the root which takes variables tduid and url (shoplink.cfm?tduid=1&url=)
I have tried to resolve it using this:
# maybe?:
RewriteRule !(^/shoplink.cfm [QSA]
but to be honest, I have not much of a clue of urlrewriting and have no idea what I am supposed to write. I just know that above will generate a nice 500 error.
I have been looking around a lot on stackoverflow and other websites on the same subject, but all I see is people trying to exclude directories, not files. In the worst case I could add the script to a seperate directory and exclude the directory from the rewriterules, but rather not since the script should really remain in the root.
Just also tried:
RewriteRule ^/shoplink.cfm$ $0 [L]
but that didn't do anything either.
Anyone who can help me out on this subject?
Thanks in advance.
Steven Esser
ColdFusion programmer
Please try to put the following line at the top of your config (after RewriteEngine on):
RewriteRule ^shoplink.cfm$ - [L]
I need to point the root domain of my hosting account to a subdirectory (joomla). I want this to be invisible (i.e. browser address bar doesn't change). Also, I need this to work when a user hits the root or a subfile/subfolder.
I've tried the following rules, which work individually, but I can't get them to work together.
This one works when no subfile/subfolder is specified:
RewriteEngine On
RewriteRule ^$ /joomla/ [L]
And this one works when a subfile/subfolder IS specified:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.+)$ /joomla/$1 [L]
I just can't figure out how to combine them.
RewriteEngine On
RewriteRule ^(.*)$ /joomla/$1 [L]
Should work (untested). The key difference between this and your second attempt is the + vs *. The + will match one or more, whereas the * will match 0 or more, so this should work also when no file/subdirectory is specified.
This should do the trick:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /joomla/$1 [L]
.* will also match an empty string. You also more than likely want to do the -d check to make sure that they aren't accessing a directory that exists (though, thinking about it, this might mess with the / matching, I don't know).