I'm using CodeIgniter 3.1.1 .
The problem is when i browse sub-directory(http://www.wap.com/demosite) where CodeIgniter installed, it always redirect to main domain and i think the problem is in .htaccess.
For example :
Domain : http://www.wap.com
Main site directory public_html/
And .htaccess file in main-directory public_html/.htaccess
RewriteEngine on
RewriteOptions inherit
ErrorDocument 500 /errors/404
ErrorDocument 401 /errors/404
ErrorDocument 403 /errors/404
ErrorDocument 404 /errors/404
RewriteCond %{HTTP_REFERER} !^http://wap.com/.*$ [NC]
RewriteRule .*\.(jpg|jpeg|gif|png|bmp|js)$ - [F,NC]
CodeIgniter installation directory
public_html/demosite/
And .htaccess file in sub-directory public_html/demosite/.htaccess
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
I'm assuming the move is a new addition?
Need to make sure that in application/config/config.php that your base_url is set to http://www.wap.com/demosite not to http://www.wap.com
This is often missed and causes these kinds of redirects
Your codeigniter htaccess should also be set to RewriteBase /demosite/
Related
.htaccess ErrorDocument 404 page not redirecting when I was using the rewrite rule. Getting 500 Internal Server Error.
Without RewriteRule the ErrorDocument is Working fine.
My Code
RewriteEngine On
<IfModule mod_rewrite.c>
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /stores/$1 [NC,L]
ErrorDocument 404 /404.html
</IfModule>
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /stores/$1 [NC,L]
The "problem" with this rule is that if you make a request for a non-existent file and that file not exist in the /stores/ subdirectory either then it will result in an endless rewrite-loop (hence the 500 Internal Server Error you are seeing) since it will attempt to rewrite as follows:
/not-exists (initial request)
/stores/not-exists (1st rewrite)
/stores/stores/not-exists (2nd pass)
/stores/stores/stores/not-exists (3rd pass)
etc.
You've not actually stated what you are trying to achieve here, but I assume /stores is a "hidden" subdirectory and you are intending to rewrite to actual files within the /stores subdirectory. This is the only way a rule like this would work with an ErrorDocument 404 directive defined in Apache.
So, when rewriting to the /stores subdirectory, you need to first check that the request would map to an actual file before issuing the rewrite. That way, any request that does not exist and does not map to a file in the /stores subdirectory will drop through to the Apache defined 404 ErrorDocument.
For example, try the following instead:
ErrorDocument 404 /404.html
RewriteEngine On
# Rewrite request to "/stores" directory if file exists in that directory
RewriteCond %{DOCUMENT_ROOT}/stores/$1 -f
RewriteRule (.+) stores/$1 [L]
# (OPTIONAL) Rewrite requests for root to "/stores/"
RewriteRule ^$ stores/ [L]
The <IfModule> container is not required (but you had the RewriteEngine directive outside of this container - which defeats the point anyway).
The RewriteBase directive is not required here if the .htaccess file is located in the document root.
It is structurally better to define your ErrorDocuments first.
I need to deny access for all excluded URLs:
mydomainname/filename.html
and redirect this request to:
mydomainname/index.php?page=filename.html
And the user should see in the address bar:
mydomainname/filename.html
And I want all styles and js scripts to work correctly.
How can I do this?
I am was trying this:
ErrorDocument 404 /
ErrorDocument 403 /
RewriteEngine On
RewriteBase /
RewriteRule ^(\w+)(?=\.).html$ index.php?page=$1.html
#if the request is for existent dirs, forbid the request
RewriteCond %{REQUEST_FILENAME} -d
RewriteCond %{REQUEST_URI} !^/?$
RewriteRule ^ - [R=403,L]
RewriteCond %{REQUEST_URI} !^/?$
RewriteRule !^index.php$ - [R,F,L]
Options All -Indexes
And I have server error 500.
Without "Options All -Indexes" js files can't be loaded and styles are not working.
So, my final .htaccess file:
RewriteEngine On
ErrorDocument 403 http://mydomainname
ErrorDocument 404 http://mydomainname
# Don't show directory listings for URLs which map to a directory.
Options -Indexes
# Set the default handler.
DirectoryIndex index.php
# Internal redirect
RewriteRule ^(\w+)(?=\.).html$ index.php?page=$1.html
# Pass all requests not referring directly to files in the filesystem to
# index.php. Clean URLs are handled in drupal_environment_initialize().
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^ / [L,R]
This solution is not deny access to mydomainname/include/myfile.php (if this file is exist), but it cover all other issues.
Search for rewrite condition in .htaccess file. You will get an idea for it. Or add RewriteRule ^(.*).(gif|jpg|png|jpeg|css|js|swf)$ /public/$1.$2 [L,NC] this.
This is my non-friendly URL: localhost/website/users/?name=UserA
Now, i tried to create a friendly URL using .htaccess file.
This is everything in my .htaccess file:
ErrorDocument 404 /movies/error404.html #For Error 404
RewriteEngine On
RewriteRule /website/users/(.*)$ /website/users/name=$1
Now, When I open localhost/website/users/UserA it opens error 404 page.
Yes mod_rewrite is enabled
Try this in your .htaccess file
#Options +FollowSymlinks
RewriteEngine On
RewriteRule ^users/([0-9A-Za-z]+)/?$ users/index.php?name=$1 [NC,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
ErrorDocument 404 http://localhost/movies/error404.html
In this cause the .htaccess file would be placed under the website directory root
Note: The requests are going to index.php file which is under the users directory if you have another filename then replace it with that one
I have a custom MVC app, where in it used IndexController naming convention, which I have built on WAMP. Today i tried it to put in to Linux (LAMP).. Strangely, it is giving error "page not found". Can anybody help. I am not good at mod rewrite,
Following is the code
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?request=$1 [L,QSA]
URL is
http://hostname/mvc/incident/add
Error is The requested URL /app01/users/public_html/mvc/index.php was not found on this server.
You need to put a / before index.php and some other stuff. Look at the example I got from Wordpress's one.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Try either adding:
RewriteBase /mvc/
just under the RewriteEngine on directive, or add a leading slash to index.php:
RewriteRule ^(.*)$ /mvc/index.php?request=$1 [L,QSA]
Hi I solved this issue by using error redirecting functionality. I put following code in my .htaccess file
ErrorDocument 403 /~renjith/mvc/index.php
ErrorDocument 404 /~renjith/mvc/index.php
and in index.php file i used, $_SERVER['REQUEST_URI'] to get thr URL with query strings
I think that ./htaccess configuration is correct. I solved it simply by adding this directive to my apache2.conf file on debian.
<Directory /var/www/html/your_app_folder>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted</Directory>
Right now I have a few folders (img, css, js, and ico) in the root directory of my website. However, I want to move them into a new directory called public_html. For example, instead of the image folder being located in /img, it would be instead located in /public_html/img. But I'm having problems doing this, and i suspect it's a problem with my .htaccess file.
Options -Indexes
Options +FollowSymLinks
RewriteEngine On
ErrorDocument 404 static/404.html
ErrorDocument 403 static/403.html
RewriteCond %{REQUEST_FILENAME} !-f
# ---------- Custom Routes ----------------
# -----------------------------------------
RewriteRule ^(js|css|img|ico)\/(.+)$ public_html/$1/$2
RewriteRule ^(.*)$ index.php?r=$1 [L,QSA]
I can access /public_html/css/style.css just fine, but when I add in that first RewriteRule line and try to access /css/style.css, it doesn't work.
Can anyone figure out why? Thanks.
Add the [L] flag to the first rule. Otherwise it drops through to the second rule and attempts to pass it in r= to index.php. Accessing it via public_html works because of the RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(js|css|img|ico)\/(.+)$ public_html/$1/$2 [L]
# Update: Try using the RewriteCond before this line
# as well as where you have it earlier
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?r=$1 [L,QSA]