I was using Capistrano to deploy my source code to beta and live server.
when I deploy it to the beta server the URL looks like deploy.abc.com/project_name/current
I just want to know the way to remove /current from the URL so it will look like deploy.abc.com/project_name. I know this should be done using .htaccess and mod-rewrite. But I have no Idea.
You can modify the VirtualHost (maybe in etc/httpd/vhosts/*.conf):
<VirtualHost *:80>
DocumentRoot /home/deploy.abc.com/www/current #this line change the url
#some code
</VirtualHost>
or the .htaccess :
<IfModule mod_rewrite.c>
RewriteEngine On
#some code
RewriteRule ^(.*)$ current/$1 [QSA,L]
</IfModule>
Related
i have edited the httpd.conf with a RewriteRule, it looks like this:
<VirtualHost myip:80>
ServerName mysite.com
ServerAlias mail.mysite.com www.mysite.com
RewriteEngine on
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]
JkMount /* mysite
...
It works fine, but when the httpd.conf is rebuilded every change i made is lost. I tried editing the pre_virtualhost_global.conf but with no success, if anybody could tell me exactly what i have to put and where i would be very grateful.
Thank you for your time.
You mentioned that there is a pre_virtualhost_global.conf file, so I assume that you have WHM/cPanel. In order to modify Apache virtual hosts you have use include files as described in WHM/cPanel's official documentation.
I am removing public from laravel url by using .htaccess i am writing the code on my htaceess file
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
htacces file is in the root of laravel and my mode_rewrite also enable
after that i am getting error Sorry, the page you are looking for could not be found. but i can still get welcome page by http://localhost/laravel/public/ please solve my issue
Your web server configuration is wrong. You should point your web server to a public directory.
For example, if you're using Apache, you should set up it like this:
<VirtualHost *:80>
ServerName myapp.localhost.com
DocumentRoot "/home/vagrant/projects/myapp/public"
<Directory "/home/vagrant/projects/myapp/public">
AllowOverride all
</Directory>
</VirtualHost>
In XAMMP, MAMP, OpenServer etc. you need just to change root directory to Laravel's public directory.
Also, don't forget to restart your web server to make everything work.
I am trying to get all http requests to go to a different local directory than where DocumentRoot points to:
The web server config:
<VirtualHost 1.2.3.4:80>
DocumentRoot /local/home/me/example.com
ServerName example.com
However, the entire (PHP) code for this site is not at DocumentRoot but rather in a subdir:
/local/home/me/example.com/code/
Currently, to access the site, I have to use URLs that include the /code/ subdir. I like to get rid of that so that http://example.com/ accesses /local/home/me/example.com/code/
I understand that the right way is to make DocumentRoot point to the subdir. My web hoster won't let me change this setting, though (in fact, that's how I had it before, when I hosted this site on my private web server where I could set the DocumentRoot just like that).
I now hope I can accomplish this with rewrites in .htaccess file(s). I just don't understand how.
My questions, in particular:
What are the rewrite rules for this?
Can I make a single .htaccess file for all paths, or do I have to have one per subdir (e.g. there are subdirs inside /code/ - do they each need an individual .htaccess file?
You can use this code in your /local/home/me/example.com/.htaccess file:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^((?!code/).*)$ code/$1 [L,NC]
(?!code/) is negative lookahead that will check if request already doesn't start with /code/ and will add this if condition is true.
I'm writing my steps and findings here so you can see what I've tried and what results I got. Any advice would be welcomed. I followed the comments in this answer.
I'm running Laravel 4, using XAMMP version 1.8.2 with PHP 5.4.19 and Apache 2.4.4 on a Windows 7 machine and I'm simply still trying to get a local instance up and running.
In my case: http://localhost/sos/sos_public/ is my main screen and that works, but when I try to get to http://localhost/sos/sos_public/signup I get this error: Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException which has been talked about a lot on the net, and then I found GaryJ stating that it might be an .htaccess issue, so I did what he suggested.
My /app/routes.php file looks like this (I've tried this with a / in front of signup too):
Route::get('signup', function()
{
return 'hello!';
});
Route::get('/', function()
{
return View::make('hello');
});
First:
Just for a laugh, see if /index.php/hello works. If so, then it's a .htaccess problem.
http://localhost/sos/sos_public/index.php/signup worked perfectly fine. So it's an .htaccess problem.
My .htaccess file looked like this:
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
And:
if you're running Apache 2.4, note the changes since previous
versions, regarding Require all granted and AllowOverride all within a
<Directory />...</Directory> block on your virtual host.
I added this in my httpd.conf file as suggested by Dalton Gore - got the Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException error (changed this directory path to /SOS/sos_public and C:/xammp/htdocs/SOS/sos_public/ and C:/xammp/htdocs/SOS/sos_public - same results):
<Directory />
AllowOverride none
Require all denied
</Directory>
<Directory /SOS/sos_public>
AllowOverride all
Require all granted
</Directory>
Next:
Check if anything in .htaccess is working
I added dsjkdsfghk to my .htaccess file and immediately got an error, so I know my .htaccess file is being used.
Then:
Try removing the IfModule conditional. As you've got access to the
host / vhost, you can soon enable that module if it's not - so it
doesn't need be checked on every request. Equally, try moving it out
of .htaccess, and into a <Directory />...</Directory> block in your
vhost - if you've got nothing else in your .htaccess it can then be
deleted as well.
Having an empty .htaccess file caused a 404 error in my browser for http://localhost/sos/sos_public/signup (http://localhost/sos/sos_public/ still worked).
Removing the .htaccess file from C:\xampp\htdocs\SOS\sos_public\ had the same results.
Then:
Try: <VirtualHost *:80> DocumentRoot
"/Users/amiterandole/Sites/laravelbackbone/public" ServerName
laravelbackbone.dev <Directory /> AllowOverride all Require all
granted </Directory> <IfModule mod_rewrite.c> Options -MultiViews
RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^
index.php [L] </IfModule> </VirtualHost>
I did that and just like Amit,
I emptied out my htaccess file and tried the above and now nothing
seems to work.
Except where his laravelbackbone.dev pointed to his Sites folder root, I just got an Error 400 - Bad request on both http://localhost/sos/sos_public/ and http://localhost/sos/sos_public/signup when I ran them in my browser.
My httpd-vhosts.conf file looked like this:
<VirtualHost *:80>
DocumentRoot "C:/xammp/htdocs/SOS/sos_public"
ServerName sos.dev
<Directory />
AllowOverride all
Require all granted
</Directory>
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
</VirtualHost>
and in my .hosts file I obviously had:
127.0.0.1 sos.dev
Lastly:
You've definitely got the conf/extra/httpd-vhosts.conf file be
included (uncommented) within the main httpd.conf?
I have this uncommented - yes.
Another link I tried but to no avail: https://stackoverflow.com/a/17778222/956975 and http://www.epigroove.com/blog/laravel-routes-not-working-make-sure-htaccess-is-working
What should I change where?
What am I missing?
Your ServerName is
sos.dev
And apache take this in consideration, you you must access your routes using:
http://sos.dev/
And NOT
http://localhost/
It might be the error of not enabling rewrite Engine in apache2
In linux,
sudo a2enmod rewrite
sudo systemctl restart apache2
In windows,
You should find httpd.conf file if it's not available in your apache look for apache2.conf file is another name for httpd.conf and enable the rewrite module for more info or here see how to do above-said procedure in this link
Lost httpd.conf file located apache
I tried to make a .htacces to simulate dynamics subdomains.
like his post :
.htaccess: mod-rewrite; subdomain
but it's impossible for me to get the expected result.
i have read several times the doc at : apache
i have no problem with : RewriteCond, RewriteRule, regular expression.
But i have problems with the subdomain.
i have this page : tododiversion.es
and for my example, I want this :
chr.tododiversion.es ==> tododiversion.es/chr/
i put .htaccess in the www folder: www/ .htaccess
and the folder "chr" is in : www/chr/
in the htacces i put :
RewriteEngine On
# host starts with something else
RewriteCond %{HTTP_HOST} ^([^\.]+)\.tododiversion\.es$ [NC]
# rewrite
RewriteRule ^(.*)$ /chr [L]
it doesn't work..
I know that urlrewritting is working because I made a simple test.
I know that RewriteCond is working because I made a simple test.
I was trying on my computer with localhost and 127.0.01 and it didn't work neither.
If someone could give me some advice it should be great!
Chris
The issue could be that apache is not properly configured to handle subdomains. Make sure that you have all subdomains set up to forward to this directory, or the .htaccess will never be executed.
<VirtualHost *:80>
ServerName domain.com
ServerAlias *.domain.com
DocumentRoot /var/www/domain.com
</VirtualHost>
Remember to restart Apache after updating your config files.
For a reference, see How to configure subdomains for Apache2 on Ubuntu?
You need to include $1 in the rewrite rule so that any URL specifics after the domain are passed on.
chr.tododiversion.es/page.html ==> tododiversion.es/chr/page.html
Based on the link you provided, the rewrite rule should be as follows:
# rewrite
RewriteRule ^(.*)$ /%1/$1 [L]