I am trying to install CI under a directory which is also on a subdomain. So my base url would look like http://subdomain.domain.com/ci/
The following htaccess works fine on root of domain but not on directory, the browser says there is a redirect loop error.
Here is my code:
RewriteEngine on
RewriteCond %{HTTP_HOST} !^sub\.domain\.com/ci/$
RewriteRule ^(.*)$ http://sub.domain.com/ci/$1 [L,R=301]
RewriteCond $1 !^(index\.php|assets)
RewriteRule ^(.*)$ /index.php?/$1 [L]
I am not very skilled with mod rewrite, any help would be appreciated! Thank you!
Inside your /ci directory your htaccess should be as follows
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f # this means if the requested file name doesnt exist
RewriteCond %{REQUEST_FILENAME} !-d # this means if the requested directory doesnt exist
RewriteRule ^(.*)$ index.php [L]
Based on your above comments that should be sufficient
Related
I'm wondering how I can redirect this:
sample.com/issues/3
sample.com/issues/4
etc.
to
sample.com/issues/index.php?id=3
sample.com/issues/index.php?id=4
etc.
UPDATE: A friend suggested this:
RewriteRule ^issues/(.*)$ issues/index.php?id=$1 [L]
But this redirects to the wrong subdirectory. E.g. it redirects /issues/4/ to /issues/4/?id=4
Strangely it seems to check out on this testing site but it's not working on my local server, nor on my live server.
Any ideas? The full .htaccess now looks like so:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^sample.com [NC]
RewriteRule ^(.*)$ http://www.sample.com/$1 [L,R=301]
Redirect /archive.php /issues/
RewriteRule ^issues/(.*)$ issues/index.php?issue=$1 [L]
Create a new .htaccess inside issues/ directory with this rule:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([\w-]+)/?$ index.php?issue=$1 [L,QSA]
I have my htaccess and it already does couple of good things (it hides www and .php in my url) but I also need to add one additional feature to it.
I have the main domain called: wdd.ie
I have a root folder called: wdd.ie
Most important files are kept in the root.
I have also the following file in the root: about.php
I love to access about.php file by calling non existing directory: www.wdd.ie/myweb/
And my full URL path looks like this: www.wdd.ie/myweb/about
I would like to access the file (stored in the root) to allow non existing directory in url but to ignore it
Could anyone help!? Please, please help!
As this new desired htaccess feature complexity is now probably beyond my skills.
<IfModule mod_rewrite.c>
DirectoryIndex index.php
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html
RewriteEngine on
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ / [L,QSA]
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
</IfModule>
If I've understood correctly you want the following url www.wdd.ie/myweb/about to offer up content from www.wdd.ie/about.php but keep the url the same?
If so, then the following should work
RewriteRule ^myweb/about$ /about.php [L]
Looked on here at all the answers regarding this issue but none fixes my issue. I have a directory called pdfs which used to contain all my .pdf files. They are now all inside pdfs/sales so trying to create a redirect for all files in the pdfs directory to look inside the pdfs/sales directory instead using a .htaccess file in the root of my site. Everything I've tried so far results in an infinite loop. Here's what my .htaccess looks like so far:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
RewriteRule ^pdfs/(.*)$ /pdfs/sales/$1 [R,NC,L]
RewriteRule ^(.*)$ /index.php?/$1 [L]
The first rule redirects all www. traffic to non-www. url. The second rule is my pdfs rule. The last rule is for redirecting all requests to index.php for seo friendly urls. Is there a conflict here? Where am I going wrong?
Thanks
You can keep your rule like this (my comment inline):
DirectoryIndex index.php
RewriteEngine on
# remove www from domain name
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
# redirect /pdfs/abc.pdf to /pdfs/sales/abc.pdf
RewriteRule ^pdfs/((?!(?:sales|rent)/).*)$ /pdfs/sales/$1 [R=302,NC,L]
# for all non-files and no-directories route to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ /index.php?/$1 [L]
Make sure to test it after clearing your browser cache.
I am having issues with htaccess redirections. Following is the issues I am having.
The root folder to which the main domain actually points has the following folder: "example"
example.com is actually internally linked to the path "root/example/" rather than "root/". This is done using the following htaccess code
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteCond %{REQUEST_URI} !^/example/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /example/$1
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteRule ^(/)?$ example/index.html [L]
The folder "exmaple" has the following subfolders: newexample, newexample_beta
If I go to the URL "example.com/newexample", the URL needs to be internally linked to "root/example/newexample". But the URL redirects me to "example.com/example/newexample/"
could you please let me know what needs to be done
I'm using codeigniter, and I tried to remove index.php from url by creating .htaccess file
and it contents:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
this way is working will at xampp server.
but when I uploaded the site, unfortunately there was a problem appeared:
I have a folder called files and it content sub folders: images, css, js, swf, upload.
and every file at those folders can't view, and the browser said there the file not found.
any help ploese.
Just make sure you exclude those too:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt|css|swf|upload)
RewriteRule ^(.*)$ /index.php/$1 [L]
This is my .htaccess file. My understanding is that for any file or directory which has access attempted and doesn't exist, it will forward onto Codeigniter.
Anything which does exist will work fine and will not require individual exclusion. This will save time and hassel each time you add a new directory or folder as it wont require you to edit this file.
RewriteEngine on
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
Works for us, but my understanding may well be incorrect. Hope it helps
try this one which i think will solve your problem ..
RewriteEngine on
RewriteCond $1 !^(index\.php|robots\.txt|files\/images|files\/css|files\/js|files\/swf|files\/upload)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
you have to tell your server not to handle those directories over to index.php and the line which work for this is :
RewriteCond $1 !^(index\.php|robots\.txt|files\/images|files\/css|files\/js|files\/swf|files\/upload)
Here is my .htaccess file - which should work for you:
Options -Indexes
Options +FollowSymLinks
# Set the default file for indexes
DirectoryIndex index.php
<IfModule mod_rewrite.c>
# activate URL rewriting
RewriteEngine on
# do not rewrite links to the documentation, assets and public files
RewriteCond $1 !^(files|css|js|swfimages|assets|uploads|captcha)
# do not rewrite for php files in the document root, robots.txt or the maintenance page
RewriteCond $1 !^([^\..]+\.php|robots\.txt|crossdomain\.xml|maintenance\.html)
# but rewrite everything else
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
ErrorDocument 404 index.php
</IfModule>
thank you. this worked fine:
RewriteEngine on
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
I have another website and next index.php I have a folder called files, and this one content alot of folders should I have to put all names of them and names of sub-directories in them?