I'm trying to get a webpage running which might not get any support anymore, so I have to fix this on my own. So in the root directory, I have this .htaccess file:
RewriteEngine on
RewriteBase /
RewriteRule ^(.*) resources/$1 [L]
So all the content gets redirected to the resources/ folder. Now this kinda works, as the frontpage shows all the static content (CSS, JS, Images). But when I try to open mydomain.com/admin, I'll get an HTTP 500. The logfile says
AH00124: Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.
The .htaccess file in the sub-dir has this content:
Options -MultiViews
RewriteEngine On
Options -Indexes
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.+)$ index.php?param=$1 [QSA,L]
For my basic Apache knowledge this does seems quite right; but is it, or do I have change Apache settings? (The VPS is a kind of PaaS-thing, so I can access/change some things)
Thank you.
Have your root htaccess rule file in following way(you need to put a condition for a check before rewriting).
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_URI} !^/resources [NC]
RewriteRule ^(.*)$ resources/$1 [L]
Then for your sub directory level htaccess file try following:
Options -MultiViews
RewriteEngine On
Options -Indexes
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.+)$ index.php?param=$1 [QSA,L]
Also in case you want to apply same rules which you have in your root directory to sub-directories then add RewriteOptions InheritBefore before RewriteEngine ON in your sub directory level htaccess file.
Related
I am currently building a PHP-based portfolio site without any frameworks whatsoever. I have created an index.php file in the root and a lot of folders namely /about, /contact, /portfolio and the like. Within each of those, I have a separate index.php file
I created a .htaccess file and in it, I have this code...
Options +FollowSymLinks
Options -Indexes
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
For some reason when I visit my site at example.com/index.php or example.com/about/index.php the .htaccess file is not working and removing it.
Any ideas why?
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
If the intention with these directives is to remove index.php from the requested URL then you are using the wrong rules! This rule would route a request for /something to index.php/something (passing the requested URL-path as path-info to index.php) providing /something does not map to a file or directory.
You have presumably structured your URLs so they map to filesystem directories from which the DirectoryIndex is served, so the above directives would seem to be entirely redundant. (?)
To remove index.php from the end of any URL
To remove index.php (the DirectoryIndex) from any URL you would need to do something like the following instead:
RewriteRule ^(.+/)?index\.php$ /$1 [R=301,L]
Test first with a 302 (temporary) redirect to avoid potential caching issues.
To clarify...
you must not be linking internally to /index.php or /about/index.php. The above directive is only for when a user or external site erroneously requests the index.php file directly.
And include trailing slashes on your internal links. eg. you should be internally linking to /about/ and /contact/ etc. (not /about or /contact), otherwise mod_dir will implicitly issue a 301 redirect to append the trailing slash.
It took a while and thanks for the suggestions by Mr White this is my solution..
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1 [L,QSA]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s(.*)/index\.php [NC]
RewriteRule ^ %1 [R=301,L]
Works perfectly now.
Thank you for everyone who took the time out to help me on this.
My CodeIgniter project is placed inside sub-folders and I want to hide those two sub-folders with .htaccess.
Everything is working fine but my current URL looks like this:
example.com/folder1/folder2/ci_project/class/function/$id
I want this to be:
example.com/class/function/$id
Now, I am using this simple .htaccess code in order to remove the index.php from URL:
Options +FollowSymLinks
RewriteEngine on
# Send request via index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
Any Ideas?
when i use the following code in htaccess file inside folder1/folder2/ci_project, it does hide the sub directories but i get the error "Object not found"
RewriteCond %{REQUEST_URI} !^/folder1/folder2/ci_project/
RewriteRule ^(.*)$ /folder1/folder2/ci_project/index.php/$1 [L]
Move your current .htaccess file from your ci_project/ to the root of domain, and replace these code inside it:
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
RewriteCond $1 !^(robots\.txt|favicon\.ico|public)
RewriteRule ^(.*)$ /folder1/folder2/ci_project/index.php/$1 [L]
</IfModule>
In this case, you should place your public files in a folder like public at the root of the domain.
You should add other folders (like public) to RewriteCond if you don’t want them to be treated by RewriteRule.
If multiple application are exist in the same domain, you might want to consider this option:
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /folder1/folder2/ci_project/index.php/$1 [L]
</IfModule>
I am creating a website where I want the members profile links as follows:
somedomain.com/someuser1/ -> somedomain.com/#!/home/someuser1/
somedomain.com/someuser2/ -> somedomain.com/#!/home/someuser2/
etc...
because i don't want to fill the root folder up with a bunch of member profile folders. Can this be done easily in the .htaccess file with rewrites?
I believe i would need to pull the 'someuser1' and 'someuser2' values and append them during the rewrite, but i'm not sure how to do that... the member folders will exist in the /home/ folder, but not the root folder...
Thanks!
Greg
Try this code in your .htaccess:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^([^/]+)/?$ /#!/home/$1 [R=302,NE,L]
Once you verify it is working fine, replace R=302 to R=301. Avoid using R=301 (Permanent Redirect) while testing your mod_rewrite rules.
Will this work? Put this in the .htaccess file. Untested
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+) /#!/home/$1 [R=301,NC,L]
I don't have much experience with htaccess. But I have this script:
Options +FollowSymLinks
ErrorDocument 404 /index.php
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*)$ index.php?doel_url=$1 [L,QSA]
But if there exists a file, he just listen to this rule.
Help!
website.nl/categorie is not a file and is not a directory.
if you need categorie to go to the file you will need to make sure it has a file extension (in your case .php) so it should be website.nl/categorie.php to avoid being redirected to the index.php page
Options -MultiViews should fix that.
I was looking for an answer, but didn't find it. I have .htaccess in root file which redirect /loremipsum/ to index.php?url=loremipsum, but, it also wants to work in subdirectories. I have a lot of them, so putting .htaccess file in everyone would be painful. Is there any way to make it working only in root folder?
if you add this rules it will only work on files and folders that didnt exist
Options -MultiViews +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ index.php?url=$1 [L]
To make your redirect rule work only in root dir use this negative lokahead based code:
Options -MultiViews +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]*)(?!/.*)$ index.php?url=$1 [L]