don't work redirect with .htaccess - apache

I work local on my machine. I have some problems with redirect through .htaccess. In my web-application I have 2 redirect through 2 .htaccess files.
I have next structure my app:
root:
application (dir)
public (dir)
index.php
.htaccess
.htaccess
In first .htaccess file has next code:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ public/ [L]
RewriteRule (.*) public/$ [L]
</IfModule>
but it doesn't work. In browser I see next picture view in browser
I change file apach2.conf and add
<Directory /var/www/my-site/>
AllowOverride All
</Directory>
but it don't help fix problem.
What I must do to it work?

Try this :
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} /public/([^\s?]*) [NC]
RewriteRule ^ %1 [L,NE,R=302]
RewriteRule ^(.*)$ public/index.php?$1 [L,QSA]

Related

htaccess redirect to new domain with parameters

I need to redirect from abc.com/param to test.bcd.com/?query=param via htaccess.
Is it correct?
RewriteEngine on
RewriteCond %{HTTP_HOST} !^(www\.)?test\.bcd\.com$ [NC]
RewriteRule .* http://test.bcd.com/?query=%{REQUEST_URI} [R=301,L]
Please try this
Options +FollowSymlinks -MultiViews
RewriteEngine on
RewriteCond %{QUERY_STRING} ^query=param [NC]
RewriteCond %{HTTP_HOST} !^(www\.)?test\.bcd\.com$ [NC]
RewriteRule ^ http://test.bcd.com%{REQUEST_URI}?%{QUERY_STRING} [R=301,L]
for redirect to index.html then try this
Please add following two lines to allow a specific file to load just in case there is no default index file setup already
Options -Indexes
DirectoryIndex index.html index.php
Note : if you have to load first php index file then you have set like
DirectoryIndex index.php index.html

Symfony .htaccess adding rule for app_MYNAME.php

i want to add another app_MYNAME.php in the web folder.
This file is nearly identical to the app.php.
The only difference is this entry:
$kernel = new AppKernel('MYKERNELNAME', false);
I want to load different configuration files with these method.
When i type in the browser:
domain.de/app_MYNAME.php/VALUE
all is fine.
Now i want to hide the app_MYNAME.php. The Result should look like:
domain.de/VALUE
The second step is the redirecting. When someone type in the browser:
domain.de/MYNAME/VALUE
it should be redirected to:
domain.de/app_MYNAME.php/VALUE
I only get a 404 or a misconfigured message.
At the end i need 3 app_MYNAME.php files (app_MYNAME1.php, app_MYNAME2.php, app_MYNAME3.php).
I hope someone could explain me, what to put in the .htaccess file.
Here is my .htaccess file:
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}/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
RewriteRule ^ %{ENV:BASE}/app.php [L]
</IfModule>
<IfModule !mod_rewrite.c>
<IfModule mod_alias.c>
RedirectMatch 302 ^/$ /app.php/
</IfModule>
</IfModule>
Try with a configuration that looks like this in your .htaccess file :
<IfModule mod_rewrite.c>
RewriteEngine On
# ... Your other stuff
# RewriteRule ^(.*)$ /app.php [QSA,L]
RewriteRule ^(.*)$ /app_MYNAME.php [QSA,L]
</IfModule>
Also, make sure that your nginx/apache host file is pointing to the web directory of your Symfony project.
Try this :
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app_MYNAME.php [QSA,L]
Maybe all app.php could convert to app_MYNAME.php in your htaccess

Cake 2.+ on shared hosting - 404 error

Since 2 days I have been trying to get my cake app working (using German 1&1 hosting). The desired address is: http://www.bzalewski.de/k/front. If you open it, you can see, it's there but without images and css. Also this: http://www.bzalewski.de/k/front/art/discover doesn't work (but it does locally with XAMPP. There is no routing, just ArtController --> public function discover()).
I followed the instructions from this article: http://bakery.cakephp.org/articles/tim_m/2007/09/20/500-errors-with-1and1-hosting-apache-1-x
My three .htaccess look like this:
./.htaccess
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^$ /k/front/app/webroot/ [L]
RewriteRule (.*) k/front/app/webroot/$1 [L]
</IfModule>
./app/.htaccess
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^$ /k/front/app/webroot/ [L]
RewriteRule (.*) /k/front/app/webroot/$1 [L]
</IfModule>
.app/webroot/.htaccess
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /k/front/app/webroot/index.php?url=$1 [QSA,L]
</IfModule>
I would appreciate any help to:
make controllers work (art/discover working)
make images and other stuff in the webroot directory work
Just to mention it: my local XAMPP installation works with standard .htaccess files without any problems.
Try adding this line in the root .htaccess (the htaccess in /k/front/ folder) after RewriteEngine On:
RewriteBase /k/front/
Edit : I did not see that you put /k/front/ everywhere in the htaccess
Then add RewriteBase / with you version of the htaccess
OR add RewriteBase /k/front/ with the default htaccess (without /k/front/ in the RewriteRules )

CodeIgniter Remove index.php with .htaccess

I've been working on this for an hour already so I figured I might as well ask.
I am trying to remove the index.php from my CodeIgniter app's URL and can not do it.
The app is running on a dedicated server in my office and I access the app through the url http://smr_local
This is my base virtual host block
<VirtualHost 192.168.1.90:80>
ServerAdmin admin#server.com
DocumentRoot "/var/www/smr.dev/app"
ServerName smr_local
ErrorLog "/etc/httpd/logs/error_log"
CustomLog "/etc/httpd/logs/access_log" common
<Directory /var/www/smr.dev/app>
Order allow,deny
Allow from all
AllowOverride All
</Directory>
<IfModule mod_rewrite.c>
RewriteEngine on
</IfModule>
</VirtualHost>
Here is my .htaccess file
RewriteEngine on
RewriteBase /
# Hide the application and system directories by redirecting the request to index.php
RewriteRule ^(application|system|\.svn) index.php/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [QSA,L]
And my config file
$config['base_url'] = "http://smr_local/";
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
Right now when I'm trying to access my base url http://smr_local/user/courses I get an error in my apache error log I get this.
File does not exist: /var/www/smr.dev/app/user
I really don't know what to try next. Any help would be appreciated.
Have you checked official user guide?
example.com/index.php/news/article/my_article
You can easily remove this file by using a .htaccess file with some simple rules. Here is an example of such a file, using the "negative" method in which everything is redirected except the specified items:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
In the above example, any HTTP request other than those for index.php, images, and robots.txt is treated as a request for your index.php file.
I have been working with Codeigniter previously and that is how I get it to work:
Here is my .htaccess (assuming you have default folder structure):
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# Removes access to the system folder by users.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
# Prevents user access to the application folder
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
# Checks to see if the user is attempting to access a valid file,
# such as an image or css document, if this isn't true it sends the
# request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>
That is relevant part of config.php:
$config['base_url'] = '';
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';
$config['url_suffix'] = '';
If this won't help, your problem likely in Apache configuration.
Then provide your httpd.conf and any other relevant configurations, not only virtual-hosts.

Change public_html directory .htaccess

My folder for public_html is /domain.com/public_html/ but i want the htaccess to redirect them to the folder /domain/public_html/www/ but still have domain.com as domain and not domain.com/www .
EDIT:
I want the subfolder www in the public_html do be the default root and not public_html itself
Any solution on this?
Here is my current htacess
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ www/$1 [NC,L]
</IfModule>
If you can only go for .htaccess, this simple one should do it;
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/www/
RewriteRule ^(.*)$ /www/$1 [QSA]
Explanation;
RewriteEngine on # Turn on mod_rewrite functionality
RewriteCond %{REQUEST_URI} !^/www/ # Don't rewrite requests that are
# already to the /www/ directory.
# If this isn't here, we'll go into
# a neverending loop.
RewriteRule ^(.*)$ /www/$1 [QSA] # Rewrite all else to the www subdirectory
# QSA = keep the query string.
EDIT: Didn't see your existing htaccess, this (minus the redundant RewriteEngine statement) should probably go at the end instead of the whole IfModule block.
Try to put this in the htaccess on the public_html folder:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ www/$1 [NC,L]
</IfModule>
OR
Edit the apache configuration (httpd.conf)
vi /usr/local/apache/conf/httpd.conf
and set the DocumentRoot of the domain as
DocumentRoot /home/user/public_html/www
Save the file and restart the httpd service.
OR (recomanded)
Take a look at this question(and it's answer) - https://stackoverflow.com/a/5891858/1361042
EDIT
Use this HTACCESS:
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/www/
RewriteRule ^(.*)$ www/$1 [NC, QSA]
</IfModule>
don't add it to yours but replace your htaccess with this one.