First of all, i'm new to FuelPHP, so it will be something very easy but i can't find the answer on the internet so i'm hoping that you guys can help me.
The thing is that i'm following THIS tutorial about FuelPHP.
I've setup wamp with an virtial directory in D:\www_ander\webshop. That is the root with the .htaccess and the index.php and the folder assets
I've got the fuel folder in the folder www_ander.
I've did what the tutorial said ( Edit the config / autoload, create the files and database ) with the following command ( i ran this in command promt from the folder D:\www_ander )
php oil generate scaffold messages name:string message:text
php oil refine migrate
I don't get any errors, and the database is created succesfully. But when i go to my website (this is localhost, i've edidted the host file of windows ):
http://webshop.nl/messages/
I get an 404, Not Found page. I even tryed it with /index/ appended to the URL, but that didn't work also.
So my question is, what did i wrong? Why isn't this working as it should?!? Is my URL wrong or is it another issue?
Mayby inrellevant, but here is the .htaccess file:
# Multiple Environment config, set this to development, staging or production
# SetEnv FUEL_ENV production
<IfModule mod_rewrite.c>
# Make sure directory listing is disabled
Options +FollowSymLinks -Indexes
RewriteEngine on
# NOTICE: If you get a 404 play with combinations of the following commented out lines
#AllowOverride All
#RewriteBase /wherever/fuel/is
# Restrict your site to only one domain
# !important USE ONLY ONE OPTION
# Option 1: To rewrite "www.domain.com -> domain.com" uncomment the following lines.
#RewriteCond %{HTTPS} !=on
#RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
#RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
# Option 2: To rewrite "domain.com -> www.domain.com" uncomment the following lines.
#RewriteCond %{HTTPS} !=on
#RewriteCond %{HTTP_HOST} !^www\..+$ [NC]
#RewriteCond %{HTTP_HOST} (.+)$ [NC]
#RewriteRule ^(.*)$ http://www.%1/$1 [R=301,L]
# Remove index.php from URL
RewriteCond %{HTTP:X-Requested-With} !^XMLHttpRequest$
RewriteCond %{THE_REQUEST} ^[^/]*/index\.php [NC]
RewriteRule ^index\.php(.*)$ $1 [R=301,NS,L]
# Send request via index.php (again, not if its a real file or folder)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# deal with php5-cgi first
<IfModule mod_fcgid.c>
RewriteRule ^(.*)$ index.php?/$1 [QSA,L]
</IfModule>
<IfModule !mod_fcgid.c>
# for normal Apache installations
<IfModule mod_php5.c>
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
# for Apache FGCI installations
<IfModule !mod_php5.c>
RewriteRule ^(.*)$ index.php?/$1 [QSA,L]
</IfModule>
</IfModule>
</IfModule>
------ UPDATE ------
I'm still looking for the answer, but i've already found an workaround. When i visit http://webshop.nl/index.php/messages/ it does work. So it seems like the .htaccess isn't fully working. But as far as i see, it should work. So do you guys know what could be wrong?
I've figured out what the problem was. Id had to do with my virtual host setup.
The thing is that i didn't specify to allow overides. So after i inserted this part in my virtual host file, it worked:
<Directory "D:\www_ander">
AllowOverride All
</Directory>
So the whole virtual host file now looks like this:
<Directory D:\www_ander\>
Order Deny,Allow
Allow from all
</Directory>
<VirtualHost *:80>
DocumentRoot "D:\www_ander"
ServerName webshop.nl
ServerAlias www.webshop.nl
<Directory "D:\www_ander">
AllowOverride All
</Directory>
</VirtualHost>
Related
I have just launched a Laravel 5.3 project on a live server and all is going well except one.
But my issue is, My websites are running on all 3 different URL.
My server is Ubuntu 16.4.
website.com
website.com/public/index.php
website.com/ any word /index.php
My .htaccess is: (This file is in the root folder)
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1%{REQUEST_URI} [R=301,QSA,NC,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
RewriteRule ^(.*)$ public/index.php$1 [L]
</IfModule>
But I just want to see my website with website.com URL only.
Seems like your Laravel app is accesible via an Apache HTTP alias. Follow these steps
Try to navigate to your expected route prepend it with /index.php/, in your case: website.com/index.php/users. If it works (no 404) then you problem is with the Rewrite Module configuration of Apache HTTP, you should follow the next steps.
Edit the file public/.htaccess.
Under the line RewriteEngine On add RewriteBase / if files are on root directory if in folder like laravel then add RewriteBase /laravel/
Try to navigate to an existing route.
i.e
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1%{REQUEST_URI} [R=301,QSA,NC,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
RewriteRule ^(.*)$ public/index.php$1 [L]
</IfModule>
Remove /public from your Laravel
create a virtual host
go to /etc/apache2/sites-available create .conf file or update 000-default.conf
<VirtualHost *:80>
ServerAdmin admin#example.com
ServerName website.com
ServerAlias www.website.com
DocumentRoot /var/www/html/index.html
<Directory /var/www/html/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} =website.com [OR]
RewriteCond %{SERVER_NAME} =www.website.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,QSA,R=permanent]
</VirtualHost>
To only match the homepage, i.e. http://domainxyz.com/ you need to match the empty path (as mod_Rewrite removes the leading /.
RewriteCond %{HTTP_HOST} ^www.domainxyz.com [NC]
RewriteRule ^$ /view.php?page=process/ [NC,L]
Try using this in your .htaccess file:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^website.com/([a-zA-Z-]*)/index.php [NC,OR]
RewriteCond %{HTTP_HOST} ^www.website.com/([a-zA-Z-]*)/index.php [NC]
RewriteRule ^(.*)$ http://www.website.com [L,R=302,NC]
Make sure you clear your cache before testing this. You will notice I've used R=302, this is a temporary redirect. If the redirect works and you're happy with it, then switch that to R=301 which is a permanent redirect.
This code worked for me. It will remove extention from your website e.g .php and all. Try it once.
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ $1.php [NC,L]
1. I understand why you are trying to change the .htaccess but this can be solved alot simpler. Revert the .htaccess file back to the Laravel standard
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
2. Move all of your folders and files apart from public and make sure they are behind your HTML folder.
3. Move all of your public folders and files out of the public folder and into your html folder
4. Tell laravel to look in your html folder instead of public by altering the server.php file
<?php
/**
* Laravel - A PHP Framework For Web Artisans
*
* #package Laravel
* #author Taylor Otwell <taylorotwell#gmail.com>
*/
$uri = urldecode(
parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)
);
// This file allows us to emulate Apache's "mod_rewrite" functionality from the
// built-in PHP web server. This provides a convenient way to test a Laravel
// application without having installed a "real" web server software here.
if ($uri !== '/' && file_exists(__DIR__.'/html'.$uri)) {
return false;
}
require_once __DIR__.'/html/index.php';
I find this solution a lot simpler than messing around with you htaccess. You also ensure all of the Laravel core files cannot be accessed from a url.
Other issue you are having (Internal pages)
This is probably due to your apache not allowing override with Laravels htaccess
Go to the command line of your server and access the apache2.conf file
cd /etc/apache2
Open the apache2.conf file with nano
sudo nano apache2.conf
Now locate the following
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
Change this to
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
Writeout the changes and exit nano.
Restart apache
sudo service apache2 restart
It should now be working :)
i am very begainer to server technologies.i know this question asked too many times but i really don't get it run.
it runs with domain.com/2.0/index.php/testbut when you remove index.php it throws
The requested URL /2.0/test was not found on this server.
Apache/2.2.15 (CentOS) Server at domain.com port 443
my project stucture
-
Public_html
--2.0(this is my project folder where ci can be located.it has sys,app,.htaccess)
--.htaccess
My domain
https://domain.com/2.0/
about the problem
i have two htaccess one at root mention above one is inside 2.0 folder
and the strange thing is what ever i write in the htaccess file it never effect anything
public_html/.htaccess
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
public_html/2.0/.htaccess
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
my httpd.conf
<VirtualHost *:443>
ServerAdmin info#domain.com
DocumentRoot /home/natural/public_html
ServerName api01.domain.net
ErrorLog /var/log/httpd/error_log
CustomLog /var/log/access_log common
SSLEngine on
SSLCertificateFile /home/natural/api01.domain.net.crt
SSLCertificateKeyFile /home/natural/api01.domoin.key
<Directory />
Options Indexes FollowSymLinks
Allow from all
AllowOverride None
</Directory>
</VirtualHost>
i search alot and follow all the answers by Stack overflow but no luck.
The directive "AllowOverride None" in httpd.conf will disable parsing of the .htaccess file within the directories specified (in this case /) -- Can you confirm that either of your .htaccess files are in fact being parsed?
If not, does modifying the Directory subsection within your httpd.conf file to:
<Directory />
Options Indexes FollowSymLinks
Allow from all
AllowOverride All
</Directory>
Solve the issue?
For more information: http://httpd.apache.org/docs/2.4/mod/core.html#allowoverride
I assume 2.0 is the new version of the site. It looks like /2.0/.htaccess is written as though it expects to be in the root folder. Try adding RewriteBase /2.0/ after engine on. You can remove it later when you replace the contents of the root folder with that of 2.0's.
The main problem is your # Handle Front Controller... rule. It'll capture any virtual URLs before they ever get to the 2.0 folder. Try changing it to this:
RewriteRule ^(?!2\.0(?:/|$)) index.php [L]
That will exclude the 2.0 folder from the current site's virtual URLs.
You do still need AllowOverride all as recommended by the other answer, and the directory should be the same as your DocumentRoot, not /.
Add this code inside root->.htaccess file
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
RewriteRule ^(?!2\.0(?:/|$)) index.php [L]
I'm managing a website written in symfony 2.2, hosted on a web hosting service.
I'm pretty much a complete neophite in web development, so I'm probably making some stupid mistake.
Anyway, I want to be able to access the site without the /web part.
Example: 'domain.com/symfony_site/web/mypage' -> 'domain.com/symfony_site/mypage'.
Let me say from the start: I cannot manually configure apache on the server, I only have FTP access to it.
I think I'm left with .htaccess files solution.
I have tried each and everyone of the solutions I found on the internet (most of them from this site) and none worked.
And yes, mod_rewrite is enabled.
I feel like the simplest solution would be to add a .htaccess file in the root directory of the site (the one which also contains the /web folder), with the following content:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /web/$1 [QSA,L]
</IfModule>
And this does seem to redirect properly, but then I get a "The requested URL web/mypage was not found on this server." if I visit 'domain.com/symfony_site/mypage'.
The desired home page 'domain.com/symfony_site' intead gives a "You don't have permission to access /symfony_site/ on this server.", so it looks like this is not even redirecting properly.
First, you need to move the .htaccess from the web directory to the root directory (the DocumentRoot).
Then, open the moved .htaccess, search all occurrences of /app and replace them by /web/app.
The .htaccess (without comments) should looks like :
DirectoryIndex app.php
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^app\.php(/(.*)|$) %{ENV:BASE}/$2 [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .? - [L]
# Rewrite all other queries to the front controller.
RewriteRule .? %{ENV:BASE}/web/app.php [L]
</IfModule>
<IfModule !mod_rewrite.c>
<IfModule mod_alias.c>
RedirectMatch 302 ^/$ /web/app.php/
</IfModule>
</IfModule>
Now your application can be correctly browsed using the project root directory as DocumentRoot.
This change may involve to adapt the way of loading your assets.
NOTE: It's a quick-and-dirty alternative assuming you cannot change the DocumentRoot of your application to make it points to the web directory.
a symfony2 app is designed to have the document-root at web/
here is an example configuration for apache vhost.
<VirtualHost *:80>
ServerName your.domain
DocumentRoot "/path/symfony/web"
<Directory "/path/symfony/web">
Options Indexes FollowSymLinks
AllowOverride All
Allow from All
</Directory>
</VirtualHost>
so your rewrite rule is not necessary
I've little to no experience working with Zend Framework 1 . Recently I was asked to make some changes to a sites functionality. So I decided that I would set up a local instance of the site to work on before deploying the changes to the live site.
The problem I am having is that when I go to the following url which is my local instance of the site: http://mysite.tld I am redirected to https://mysite.ie and I cannot figure out why.
Is it something to do with the htaccess file? because I removed the contents of this file in order to see if it had any impact and no joy.
Which made me thing that perhaps in Zend there is some setting which controls the environment?
This is my vhosts file on WAMP:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot "C:\wamp\www\mysite.tld\public
ServerName mysite.tld
ErrorLog "logs/mysite.tld"
CustomLog "logs/mysite.tld" common
<directory "C:\wamp\www\mysite.tld\public">
Options Indexes FollowSymLinks
AllowOverride all
Order Allow,Deny
Allow from all
Allow from 127.0.0.1
</directory>
</VirtualHost>
This is my htaccess file
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://www.mysite.tld/$1 [L,R=301]
RewriteCond %{HTTP_HOST} !^www\.mysite\.tld$ [NC]
RewriteRule ^(.*)$ https://www.mysite.tld/$1 [L,R=301]
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
If you require any more details from the project I can post them here, I'd appreciate any help as I am at a loss as to whats going on.
The following rule performs the redirect from http to https equivalent
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://www.mysite.tld/$1 [L,R=301]
This one redirects to www.mysite.tld if domain name is not already that one
RewriteCond %{HTTP_HOST} !^www\.mysite\.tld$ [NC]
RewriteRule ^(.*)$ https://www.mysite.tld/$1 [L,R=301]
If you're running it locally, you should comment those 4 lines of code.
Then, you have to clear your browser's cache to see it working (because your old rules are now in cache).
I know this question is more appropriate for Server Fault but unfortunately I was banned for poor quality questions (I was down voted on 2-3 questions I asked.) So the next best place to ask these questions are here.
I have two problems related to CodeIgniter routing.
The first problem is that I can't seem to get rid of index.php in the url. I followed the instructions on how to remove it. I have the following mod rewrite code in my .htaccess file (see below) at the root of my WAMP server (CI is located at the root, not in its own folder). I have uncommented this line in httpd.conf file LoadModule rewrite_module modules/mod_rewrite.so. I deleted index.php from $config['index_page'] = "index.php";. And I restarted all WAMP services.
My second problem is that I have a controller called search and a method called index. I would like to change the resultant URL from http://localhost/index.php/search/index to http://localhost/search/whatever_im_searching_for. I tried the following custom route in my routes.php file but it did not work: $route['search/(.*)'] = "search/$1";
RewriteEngine On
# Put your installation directory here:
# If your URL is www.example.com/, use /
# If your URL is www.example.com/site_folder/, use /site_folder/
RewriteBase /
# Do not enable rewriting for files or directories that exist
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# For reuests that are not actual files or directories,
# Rewrite to index.php/URL
RewriteRule ^(.*)$ index.php/$1 [PT,L]
I am struggling to understand the code in .htaccess and on how to use CI's custom routing. Any assistance will be greatly appreciated. Thank you in advance.
EDIT 1
Edit your htaccess like this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ index.php?/$1 [L]
RewriteCond %{REQUEST_URI} ^LoginTut.*
RewriteRule ^(.*)$ index.php?/$1 [L]
RewriteCond $1 !^(index\.php|images|table-images|js|robots\.txt|css|captcha)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 index.php
</IfModule>
To have your searchterms in the url you can look at this:
https://stackoverflow.com/a/12070284/1379394
Second problem:
$route['search/(:any)'] = "search/index/$1";
Check Apache's default config file. On WAMP it's probably in
<WAMPSERVER_HOME>\bin\apache\Apache2.2.xx\conf
If it looks like this:
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
then change both:
AllowOverride None
to:
AllowOverride All
I had the same problem and I fixed only by write in my .htaccess:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]
and it's working perfectly.