htaccess rewriting outside the root - php

I'm trying to rewrite from this url :
my domain/myapp/index.php?lang=es
to:
my domain/myapp/es/
with the following commands on the .htaccess file on the root:
RewriteEngine On
RewriteRule ^myapp/([a-zA-Z0-9_-]+)$ index.php?lang=$1
RewriteRule ^myapp/([a-zA-Z0-9_-]+)/$ index.php?lang=$1
but i didn't succeed

Your code has to work fine.
If you are using Apache server, make sure it is configured right:
Make sure this string is uncommented in httpd.conf:
LoadModule rewrite_module modules/mod_rewrite.so
Make sure that there is:
AllowOverride All
in the Directory section instead of:
AllowOverride None
Section should look like:
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
llow from all
</Directory>
With correctly configured server your .htaccess file works fine on my machine.

Related

error document not geting redirect in wamp server

I'm using wamp server 3.0.4 and apache version 2.4.18.I want to redirect 404 pages to custom pages. I have enabled LoadModule rewrite_module modules/mod_rewrite.so in apache/conf/httpd.conf and changed in apache/conf/httpd.conf:
<Directory "c:/wamp64/www/">
Options +Indexes +FollowSymLinks
AllowOverride all #none to all
Require local
</Directory>
In httpd.vhost
<VirtualHost *:80>
ServerName testblog
DocumentRoot c:/wamp64/www/testblog
<Directory "c:/wamp64/www/testblog/">
Options +Indexes +FollowSymLinks +MultiViews
AllowOverride All
Require local
</Directory>
</VirtualHost>
and restart the server.
In my htaccess file I have the following code
ErrorDocument 404 https://www.test.com/not-found.html
RedirectMatch 301 /learn https://www.test.com/not-found.html
But not able to redirect .What I missed here
Keep mod_rewrite enabled and then trying this in your .htaccess file:
Add the following to it at the top:
RewriteEngine On
RewriteBase /
RewriteRule ^learn https://www.test.com/not-found.html [R=302,L]
RedirectMatch uses mod_alias, so make sure you have enabled that, it should be enabled automatically, but rarely it might not be, so enable it and try your redirect. Even after that, if it does not work, stick with the above. Let me know if you have any questions.

Symfony 3, domain name shows Directory Structure

I know this question is asked a lot but I read all the questions related to this but they didn't solve my problem.
I just deployed a Symfony 3 web app and I followed the Symfony server configuration documentation just to find out that the www.domain.com displays the directory structure!
Here's the configuration that I used of file /etc/apache2/sites-available/site.com.conf:
<VirtualHost *:80>
ServerName domain.tld
ServerAlias www.domain.tld
DocumentRoot /var/www/project/web
<Directory /var/www/project/web>
AllowOverride None
Order Allow,Deny
Allow from All
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php [QSA,L]
</IfModule>
</Directory>
ErrorLog /var/log/apache2/project_error.log
CustomLog /var/log/apache2/project_access.log combined
I can see the app when I go to www.domain.com/web and www.domain.com/web/app.php
I want to be able to visit www.domain.com and see the app.
Change the line:
AllowOverride None
to next one:
AllowOverride All
Remove section <IfModule mod_rewrite.c> And use standard Symfony's .htaccess file.
Also you need to set up PHP as module for your apache. Be sure to have uncommented line in http.conf that loads PHP module:
LoadModule php7_module libexec/apache2/libphp7.so
You are missing your DirectoryIndex app.php or DirectoryIndex dev_app.php contained in your directory tag. This will cause apache to load app.php if a file has not been requested.
https://httpd.apache.org/docs/2.0/mod/mod_dir.html
<Directory /var/www/project/web>
DirectoryIndex app.php
...
</Directory>
Also make sure mod rewrite is enabled.
a2enmod rewrite
You may have to use sudo.
One final note:
Options -MultiViews should be contained inside the <Directory> for use all the time and not just when mod_rewrite is enabled.

Htaccess ignored on live server

I'm using a .htaccess file to use clean url's, Everything is working fine on my localhost, but on the production server my .htaccess is ignored..
I have an index.php entry point which requires the files needed.. But as you can see when you browse to
http://mindstretchscan.eu/overzicht , it's trying to load the required page directly. but not the index.php.
http://mindstretchscan.eu?page=overzicht is working! and it's the same page..
This is the top of my .htaccess
<ifModule mod_rewrite.c>
Options +FollowSymLinks -MultiViews
RewriteEngine on
Any idea what I might be doing wrong? Pulling my hairs out on this one. Thanks!
Make sure mod_rewrite is enabled
#sudo a2enmod rewrite
#/etc/init.d/apache2 restart
You also need to enable the use of .htaccess files by changing AllowOverride None to AllowOverride FileInfo. For the default website, edit /etc/apache2/sites-available/default
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
And make sure you restart apache again.

How to fix permalinks not working with Vagrant and Wordpress?

I am using Vagrant to build up a little Wordpress development VM. When I select permalinks (postname) then the page from an article doesn't load. However, when I select the standard link (i.e page id) all is working good.
I've used the service PuPHPet to build the VM.
My settings can be found here
I am using Wordpress 3.9.1 and Apache2
I've enabled mod_rewrite be executing:
a2enmod rewrite
And my .htaccess file from Wordpress is as follows:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /svisa/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /svisa/index.php [L]
</IfModule>
# END WordPress
it has the following permissions and ownership:
-rw-rw-rw- 1 vagrant www-data 248 May 30 14:52 .htaccess
My virtualhost file for the site (/var/www/svisa/) can be found here.
from my host computer, I browse to the site via adress: http://wpdev-vm/svisa/
where wpdev-vm is the name of the vm.
Does anybody know what I am missing to make the permalinks work?
I solved the problem myself.
In the default apache configuration, under /etc/apache2/sites-enabled, where mine is called 15-default.conf
This was declared under the document root:
<Directory "/var/www">
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>
I had to change AllowOverride None to AllowOverride All. Thus you'll get the following:
<Directory "/var/www">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
Allow from all
</Directory>
After that, the permalinks started working.
The (correct) answer above says that you need to change AllowOverride None to AllowOverride All in your xxx-default.conf file found in the /etc/apache2/sites-enabled directory.
However, in my vagrant box (precise64) none of the allowOverride or <Directory /var/www/>... code was present to begin with in the default.conf file.
I ended up having to add all of it between the VirtualHost tags, like below:
<VirtualHost *:80>
# Other stuff
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
And then having to restart apache, like below, for it to work.
sudo service apache2 restart

Zend Server Community Edition .htaccess issue

I am a new user of Zend Server. For some reason Apache is not reading my htaccess file in the project folder. please check my settings:
Document root:C:\Program Files\Zend\Apache2\htdocs\
project folder: C:\Program Files\Zend\Apache2\htdocs\project1\website\
htaccess path: C:\Program Files\Zend\Apache2\htdocs\project1\website.htaccess
Example to of rewrite rule in htaccess:
RewriteRule ^([a-zA-Z0-9\-]*)-([0-9]*)-([0-9]*)\.php$ /project1/website/index.php?cat=$2&page=$3 [L]
changes in httpd.conf file:
LoadModule rewrite_module modules/mod_rewrite.so
<Directory "C:\Program Files\Zend\Apache2/htdocs">
Options Indexes FollowSymLinks
AllowOverride ALL
Order allow,deny
Allow from all
</Directory>
The index page is working fine
http:// localhost/project1/website/
You should go to httpd.conf file in your apchachi folder/conf and change AllowOverride none to AllowOverride ALL after restart apachi server.Hope it work.

Categories