I can't configure routing project in Yii is 3 days, all tried to help ...
I have:
/var/www/ - project
/var/www/yii - yii framework
./htaccess
RewriteEngine On
# Put your installation directory here:
# If your URL is www.example.com/, use /
# If your URL is http://localhost/begin/, use /begin/
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]
index.php finds.
./var/www/protected/config/main.php
'urlManager'=>array(
'urlFormat'=>'path',
'showScriptName' => false,
'rules'=>array(
'/'=>'/view',
'//'=>'/',
'/'=>'/',
),
),
When I enter for example 107.170.91.28/site/contact then displays an error 404.
URL of server 107.170.91.28
On the local server. all works.
If I enter this URL 107.170.91.28/index.php/site/contact or 107.170.91.28/index.php?r=site/contact - it works.
Ask for help, because I tried all methods set.
If this is happening only on server it is either because you have configured Apache to ignore .htaccess directives on your server, or because you do not have Rewrite module loaded/installed
Either you can configure the apache conf to turn on by changing in /etc/apache2/apache2.conf (location may be different depending on OS , you can of course turn it only for application directory only as well
<Directory>
...
AllowOverride None
....
</Directory>
to
<Directory>
...
AllowOverride All
....
</Directory>
for enabling rewrite module you can do ( may vary depending on OS)
a2enmod rewrite
Restart apache2 after
/etc/init.d/apache2 restart
or
service apache2 restart
Related
I have a project that has a 'public' and 'private' folder structure that sit at the same level inside the main project root folder (see attached image).
I would like so that the local server (in this case MAMP) automatically defaults to the 'public' folder as the domain root. Is it best to do this is in php or in Apache?
Also, when I upload the site to a production server the domain name is going to be set on the 'public' folder, so I'd ideally like a solution that means I when I upload the site this will still be the case - i.e. www.example.com will be the 'project/public' folder.
This is all new to me so am at a bit of loss as to the best way to approach this.
Basically all you need is to create a virtual host configuration file and enable the port in Apache configuration file on which you're application is going to listen to the requests. I've never used MAMP so am giving you an example of vhost configuration on Linux machine
Create a conf file in /etc/httpd/conf.d/
vim /etc/httpd/conf.d/example.conf
This file will tell Apache server what will be the document root for
a specific port. PORT can be any available port other then reserved
Ports (0-1023)
<VirtualHost *:80>
KeepAlive On
DocumentRoot "/var/www/example/public"
<Directory "/var/www/example/public/">
Options -Indexes +FollowSymLinks +MultiViews
AllowOverride None
Order allow,deny
Allow from all
# enable mod_rewrite
RewriteEngine on
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</Directory>
LogLevel Warn
ErrorLog /var/log/httpd/example-error.log
CustomLog /var/log/httpd/example-access.log combined
Add this Port No PORT in Apache conf file
(/etc/httpd/conf/httpd.conf)
Listen PORT
Restart Apache Server
Like XAMP & WAMP, MAMP should also have a GUI to configure the Apache Server. You can locate the location/folder where these vhost configuration are save and you can modify that file directly through any Text Editor
You can refer these too
Configuring Virtual Hosts With MAMP
Adding a virtual host in MAMP for Mac
I've tryed to follow Yii2 Official Guide to configure Apache-2.4x64 for enablePrettyUrl option. My issue is that I've got 500 Server Error when trying to access localhost/about/web/ in my browser. I've placed .htaccess in my about/web folder.
Here's it's configuration:
# Set document root to be "basic/web"
DocumentRoot "d:/openserver/domains/localhost/about/web"
<Directory "d:/openserver/domains/localhost/about/web">
# use mod_rewrite for pretty URL support
RewriteEngine on
# If a directory or a file exists, use the request directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Otherwise forward the request to index.php
RewriteRule . index.php
# ...other settings...
</Directory>
Maybe something wrong with path to about/web? I have this error only on my Windows machine.
Directory and DocumentRoot are not allowed in the .htaccess file, they should be in the apache configuration (or in your VirtualHost config file).
In your case, the .htaccess file is being read, that is why it gives youa error 500 (the file is read but it containt systax errors or bad commands). Therefore, it should be enough to remove the 'DirectoryandDocumentRoot` commands and leave the file just with:
# use mod_rewrite for pretty URL support
RewriteEngine on
# If a directory or a file exists, use the request directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Otherwise forward the request to index.php
RewriteRule . index.php
Please, make sure that mod_rewrite is enabled in your apache installation.
I need some help with laravel 4 application i need to remove Index.php from url i have tried the solution that has been mentioned in laravel documentation
Pretty URLs
Apache
The framework ships with a public/.htaccess file that is used to allow URLs without index.php. If you use Apache to serve your Laravel application, be sure to enable the mod_rewrite module.
If the .htaccess file that ships with Laravel does not work with your Apache installation, try this one:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
any Suggestions :) ?
FOR LAMP SERVER
Try the following steps,
Activate the mod_rewrite module with,
sudo a2enmod rewrite
and restart the apache
sudo service apache2 restart
To use mod_rewrite from within .htaccess files (which is a very common use case), edit the default VirtualHost with
sudo nano /etc/apache2/sites-available/000-default.conf
Search for “DocumentRoot /var/www/html” and add the following lines directly below:
<Directory "/var/www/html">`
AllowOverride All
</Directory>
Save and exit the nano editor via CTRL-X, “y” and ENTER.
Restart the server again:
sudo service apache2 restart
this worked for me
<Directory "/var/www/html">`
AllowOverride All
</Directory>
uncomment 'LoadModule rewrite_module modules/mod_rewrite.so' in apache httpd.conf
in 'public' folder check .htaccess file (created by default)
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
I have read long posts and threads but nothing works then i found this and it works for me.
The easiest way to do this (and the way I always use) is to open up your Command prompt or Terminal and cd into the main directory of your project then run "php artisan serve". That's it. You're done. Don't believe me? Check out http://localhost:8000 and admire your Laravel work.
http://michaelbrooks.co.uk/post/laravel-localhost-removing-public-index-php
just go to your apache settings folder, i use wamp so myne is
C:/wamp/bin/apache/apache2.4.9/conf/httpd.conf - file
// located on line 154 precisely...
#LoadModule rewrite_module modules/mod_rewrite.so
// to
LoadModule rewrite_module modules/mod_rewrite.so
restart WAMP and BOOM!.. it works.
mod_rewrite apache module may not be enabled by default. enable it and retry.
Try this:
a2enmod rewrite
And it will works
I have three web servers on three separate computers. I am trying to install a php application that rewrites all url requests to index.php (front controller pattern). The following .htaccess works on two out of the three web servers:
RewriteEngine On
# Redirect everything to the Front Controller
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule !^(css|images|files)/ index.php [NC,L]
So, when I visit http://example.com/hithere, index.php is called and I can then parse the originally requested url (hithere) to figure out what controller to send it to.
However, for some unknown reason, the above .htaccess file doesn't work on the third webserver. Instead, when I access http://example.com/hithere, I get a 404 not found error in my browser that says this:
The requested URL /full/path/to/application/index.php was not found on this server.
So, based on the above error, I can tell that it's actually trying to redirect to index.php. But the file that the browser lists in the /full/path/... below is actually on my web server - so I have no idea why it can't find it. Could someone please help me and tell me what I'm doing wrong?
Edit: I don't know if something in the httpd.conf could be conflicting, but here are the settings I have in httpd.conf for the directory that this application is in
Alias /myapp /full/path/to/my/app
<Directory /full/path/to/my/app>
Order allow,deny
AllowOverride All
Allow from all
</Directory>
Edit 2: I noticed something peculiar in the Apache logs. It looks Apache is appending index.php, which I am trying to redirect traffic to, to the DocumentRoot:
File does not exist: /document/root/full/path/to/my/app/index.php
When it should be going to:
/full/path/to/my/app/index.php
So I basically need to tell htaccess to ignore the document root. I tried this by specifying this in my .htaccess file:
RewriteBase /full/path/to/my/app/
But it's still searching the document root for index.php :/ Is there a way to reset the DocumentRoot or tell htaccess to ignore it when rewriting to index.php? Even when I use the absolute path in the RewriteRule, it still appends it to the document root.
RewriteEngine On
# Redirect everything to the Front Controller
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule !^(css|images|files)/ /full/path/to/my/app/index.php [NC,L]
It doesn't make sense to me... Can someone please help?
Thanks
So, based on the above error, I can tell that it's actually trying to
redirect to index.php. But the file that the browser lists in the
/full/path/... below is actually on my web server - so I have no idea
why it can't find it.
Assuming it's a *nix alike system, you might want to check file permissions and make sure that the webserver has read access to the file.
You also need to check the DocumentRoot parameter in httpd.conf
Look for something like this in the file and make sure it's correct. That is also where apache will be getting it from.
DocumentRoot "/var/www/html/path/to/whatever"
Also I would disable SELinux if it's on and you really don't need it because it causes weird problems too.
First enable rewrite module in apache by using $ sudo a2enmod rewrite then restart web server by $ sudo systemctl restart apache2
Put following code in your virtual host.
<Directory /var/www/html/your_app_folder>
Order allow,deny
AllowOverride All
Allow from all
</Directory>
then add following code in your .htaccess file
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
i have created first Symfony application but the url is so large
http:// ip address/repair/web/app_dev.php/home
http:// ip address/repair/web/app.php/home
i want to make it as http:// ip address/repair/home
here is httpd.conf of apache2
NameVirtualHost something ip address
ServerName "repair"
DocumentRoot "/var/www/repair/web"
<Directory "/var/www/repair/web">
DirectoryIndex app.php
AllowOverride None
Order allow,deny
Allow from All
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php [QSA,L]
RedirectMatch permanent ^/app\.php/(.*) /$1
</Directory>
my .htaccess of in web folder of symfony contains
Options +FollowSymlinks
RewriteEngine On
# Explicitly disable rewriting for front controllers
RewriteRule ^app.php - [L]
RewriteRule ^app.php - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php [QSA,L]
i have reloded the mod-Rewrite of apache2 too
iam getting error
The requested URL /repair/home was not found on this server.
Apache/2.2.20 (Ubuntu) Server at ip address Port 80
If you want to access site by ip you need to copy your code to "localhost" directory (/var/www, e.g.)
The AllowOverride None line in your Apache config is causing the .htaccess file to be ignored.
If you replace it with AllowOverride All Apache will follow the directives in your .htaccess file.
You can find more information about AllowOverride here
Double-check that you actually have mod-rewrite loaded for Apache. On a Debian 6 install with Apache 2, the module was available, but it wasn't loaded. In order to load it, you can add a symlink in the mods-enabled directory to the module in the mods-available directory like this:
root#server:/etc/apache2/mods-enabled# ln -s ../mods-available/rewrite.load ./rewrite.load
Then you'll need to restart Apache2 to get it to reload its configuration. On Debian that would be sudo service apache2 restart