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).
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'm trying to set up my local development environment on a new Mac. It's the first one I've got and I'm not really sure about different stuff.
I've set up most of the things correctly and now I can access my websites like this:
localhost/~carlo/website.com/
In the case of a Codeigniter I have to put the index.php at the end.
The .htaccess I normally use is like this:
RewriteEngine on
RewriteBase /~carlo/website.com/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|cache|captcha|fonts|forum|media|img|min|css|js|scripts|images|uploads|docs|robots. txt|sitemap.xml|sitemap|public|tools|wpblog|assets|xd_receiver.htm)
RewriteRule ^(.*)$ index.php/$1 [L]
But it's not enough.
I added this to /private/etc/apache2/extra/httpd-vhosts.conf:
DocumentRoot "/Users/carlo/public_html" ServerName "localhost" ErrorLog "/private/var/log/apache2/dummy-host.example.com-error_log" CustomLog "/private/var/log/apache2/dummy-host.example.com-access_log" common
DocumentRoot "/Users/carlo/public_html/website.com" ServerName tobecontinuedcomic.com AllowOverride All Options +FollowSymLinks Order allow,deny Allow from All
But still nothing. Any help?
It looks like the RewriteCond is incorrect - I'm guessing you need this instead:
RewriteCond %{REQUEST_URI} !^(index\.php|cache|captcha|fonts|forum|media|img|min|css|js|scripts|images|uploads|docs|robots.txt|sitemap.xml|sitemap|public|tools|wpblog|assets|xd_receiver.htm)
RewriteRule ^(.*)$ index.php/$1 [L]
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>
SO I set up https to work on my site. the main page works. https://mysite.com but when you try to go to a sub folder like https: //mysite.com/join you receive the following error.
Not Found
The requested URL /join/index.php was not found on this server.
Apache/2.2.8 (CentOS) Server at mysite.com Port 443
It's as if it can't understand codeigniter. Below is my htaccess files.
RedirectMatch 404 /\\.git(/.*|$)
RewriteEngine On
Options +FollowSymLinks
RewriteBase /
RewriteCond $1 !^(index\.php|images|img|js|css)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https: //%{SERVER_NAME}%{REQUEST_URI} [R=301]
ErrorDocument 404 /system/error/404page.html
I doubled check the ssl virtualhosts with several other developers and it is set up right. It's weird that the home page works and nothing else. I'm guess it is because the home page has the codeigniter index.php to look at.
I set up the base URL as https://mysite.com.
Is there some settings in codeIgniter that I am missing?
I figured it finally.
in the httpd.conf I had to change this:
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
To this:
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
I knew it was something this small and annoying. Thanks for the help guys!
Change this line :
RewriteRule ^(.*)$ index.php?/$1 [L]
to :
RewriteRule ^(.*)$ /index.php?/$1 [L]
The .htaccess would otherwise be redirected relatively to a index.php in the join folder, which off course is not there.
I'm running a portable server through usb stick. The thing is I also have WAMP installed in my local machine and Apache somehow gets started on windows startup, because of some random reason which I don't recall now and it can't be changed. I want to prepare my portable server in situations like this, so closing httpd.exe from process and starting my portable server is not an option. Anyway, because of already active httpd.exe my portable server's WordPress site can only be accessed through localhost:81 - this is a problem as WP site is very dependent on the URL and I don't want to include the url with port on WP database.
Here is what I want to do through .htaccess:
On any path except for error.php file check if not port 80
If not port 80 redirect to /error.php?code=port
It it possible for it to have priority over WP redirection or URL handling?
In the error.php I provided info on how to manually close httpd.exe and such so my family and friends can access the portable site. It's sort of like a gallery and calender application for events and other such stuff...
Please help? I'm I can't figure it out at all. I know others may not have apache already running, but I want to prepare for such a situation.
Something like the following, but the following doesn't work.
# BEGIN WordPress
<IfModule mod_rewrite.c>
<If "%{SERVER_PORT} = 80">
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</If>
<Else>
RewriteEngine On
RewriteRule ^(error.php)($|/) - [L]
RewriteRule ^(.*)$ /error.php?code=port [L]
</Else>
</IfModule>
# END WordPress
# <If "%{SERVER_PORT} = 80">
RewriteEngine On
RewriteBase /
RewriteCond %{SERVER_PORT} ^80$
RewriteRule ^index\.php$ - [L]
RewriteCond %{SERVER_PORT} ^80$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
#</If>
#<Else>
RewriteEngine On
RewriteCond %{SERVER_PORT} !^80$
RewriteRule ^(error.php)($|/) - [L]
RewriteCond %{SERVER_PORT} !^80$
RewriteRule ^(.*)$ /error.php?code=port [L]
#</Else>
You can try this apache config
RewriteEngine on
RewriteCond %{SERVER_PORT} !^80$
RewriteRule ^(.*) http://%{SERVER_NAME}:80%{REQUEST_URI}
RewriteCond %{SERVER_PORT} ^80$
RewriteRule .* http://example.com/index.php [L]
The 1st paragraph redirects if its NOT 80
the 2nd is just an alternative you can try, if you want only that matches 80
for more info on rewrites,
http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html
VirtualHosts are what you are looking for.
A small example of how you can achieve http://wplocal/ or http://wp.local/ to point to /var/www/wp AND http://localhost/ or http://http.local to point to /another/root/path.
NameVirtualHost *:80
<VirtualHost *:80>
ServerAdmin wp#you.com
DocumentRoot "/var/www/wp"
ServerName wplocal
ServerAlias wp.local
ErrorLog "/somepath/here"
</VirtualHost>
<VirtualHost *:80>
ServerAdmin you#you.com
DocumentRoot "/another/root/path"
ServerName localhost
ServerAlias http.local
ErrorLog "/logs/path"
</VirtualHost>
See this for cool images that explain that stuff.
Hope that helped.