I am trying to redirect one page in cakephp. My guess is that .htaccess is the way to do this.
I'm trying to redirect from /consultation to /pages/consultation2016
I have this:
Redirect /consultation http://thep.ca/pages/consultation2016
<IfModule mod_rewrite.c>
RewriteEngine on
php_value post_max_size 70M
php_value upload_max_fiesize 70M
RewriteBase /app
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
Redirect without touching .htaccess:
CakePHP 2 (documentation):
Router::redirect('/consultation','http://thep.ca/pages/consultation2016');
CakePHP 3 (documentation):
$routes->redirect('/consultation','http://thep.ca/pages/consultation2016');
Related
Found a similar question
Cakephp 3 .htaccess File Configuration
but no answer there.
My GIT repo structure
ROOT
- .htaccess
- /htdocs (CakePHP 3 app)
- - .htaccess
- - /webroot
- - - .htaccess
ROOT .htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ htdocs/ [L]
RewriteRule (.*) htdocs/$1 [L]
</IfModule>
htdocs .htaccess (default)
# Uncomment the following to prevent the httpoxy vulnerability
# See: https://httpoxy.org/
#<IfModule mod_headers.c>
# RequestHeader unset Proxy
#</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^(\.well-known/.*)$ $1 [L]
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
htdocs/webroot .htaccess (default)
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
https://***.com/bestprice.com/ (GIT repo location)
I am actually redirected to htdocs (htdocs not displayed in url, just like I need), but get a Missing Controller error.
Bestprice.comController could not be found.
https://***.com/bestprice.com/htdocs/ works fine
I have tried many different ways and this is the best result I could achieve.
Could you please tell me what I am doing wrong? Thanks a lot for your help
I have two identical versions of a website, both using different AWS EC2 instances(staging xx.xx.xx.xx and production xxx.xxx.xxx.xxx). I want to create a 301 redirect that redirects all users from the staging site to the production site, UNLESS they are visiting from my IP. I thought this was a relatively simple task, but I have attempting to make this work for the last couple hours with no resolution. I am hoping that someone here will be able to point me in the right direction. Currently, the redirect works for visitors to the homepage http://xx.xx.xx.xx, but it does not work for other pages such as http://xx.xx.xx.xx/page1 or the ec2 public DNS like http://ec2-xx-xx-xx-xx.us-west-1.compute.amazonaws.com/ Here is my entire .htaccess file, the redirect I added is the last one. Any help you could give me would be much appreciated!!
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
php_value upload_max_filesize 64M
php_value post_max_size 64M
php_value max_execution_time 300
php_value max_input_time 300
# END WordPress
RewriteEngine on
RewriteRule ^(.*)$ http://newsite.com/$1 [L,R=301,NC]
RewriteBase /
RewriteCond %{HTTP_HOST} !newsite.com$ [NC]
RewriteCond %{REMOTE_ADDR} !=xxx.xxx.xxx.xxx
Thanks for your help, I wanted to post the solution I found in a wordpress forum here:
https://wordpress.org/support/topic/htaccess-help-301-redirects-not-working/
Thanks to #markrh for his answer. The problem was that I needed to move my 301 redirects above the WordPress section at the top. My rules were never getting reached cause the WordPress part catches all of them.
I have a classic Larevel 5 project structure and I need to redirect all requests to public/.
I am on a classic hosting environment so public/ is a subfolder of my document root.
I shall imagine it can be done via .htaccess but I still need to figure out how. Anyone can help?
Thanks
There are two solutions:
1. Using .htaccess with mod_rewrite
RewriteEngine on
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [L]
2. You can add a index.php file containing the following code and put it under your root Laravel folder (public_html folder).
<?php
header('Location: public/');
You don't need to change anything in Laravel's default public/.htaccess file.
Just create a new .htaccess in the same level your public folder and add the following content to it:
DirectoryIndex index.php
RewriteEngine On
RewriteRule ^$ public/index.php [L]
RewriteRule ^((?!public/).*)$ public/$1 [L,NC]
That simple!
This is an extract from another answer which may also help you.
--
Modify your public_html/.htaccess to redirect all requests to the public subfolder.
# public_html/.htaccess
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect All Requests To The Subfolder
RewriteRule ^ /public
</IfModule>
Make sure you have the proper public_html/public/.htaccess (GitHub).
# public_html/public/.htaccess
<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]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization}
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
If you use cPanel, then:
1.Go to folder:
/var/cpanel/userdata/my_domain
2.Edit the both domains:
my.domain and my.domain_SSL
Add to the documentroot section /public:
documentroot: /home/user/public_html/public
3.Rebuild Apache config:
/scripts/rebuildhttpdconf && service httpd restart
if you using apache , add .htaccess file to your root directory with this lines :
RewriteEngine on
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [L]
and make sure your apache redirect and rewrite modules is working fine .
you can use vhost to redirect the all request to your public directory with set public as root of your project .
The ideal scenario is to have /home/user/public as a symlink from /home/user/laravel/public.
I would redirect the whole dir "https://sub.domain.ext/dir1" to another location on a different machine "https://sub1.domain.ext/dir1", I'm using in /.htaccess the following rule with no success:
The page simply doesnt't redirect.
Rewriterule ^dir1/(.*) https://sub1.domain.ext/dir1/$1 [R=301,L]
# this is the whole ht access
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} ^Morfeus
RewriteRule ^.*$ - [F]
</IfModule>
# supress php errors
php_value display_errors off
# force https
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://sub.domain.ext/$1 [R,L]
any tips?
Scenario: ubuntu+apache
others htaccess rules worsk fine
thx
Deleting the htaccess file in the dir1/, the problem was solved.
I'm trying to get aphdigital.org/GVH/ to redirect to gvh.aphdigital.org, and aphdigital.org/GVH/something/ to gvh.aphdigital.org/something/ but I'm having quite a lot of difficulty. I tried the code from this question, but it's not working. The commented-out code blocks below also show failed attempts at a redirect. What am I doing wrong? I would enable logging if I had access to httpd.conf, but I only have FTP access. I know apache is reading this file, because syntax errors seem to cause 500 errors.
Here's my .htaccess file:
# Remember to enable display_errors on development environments only.
<IfModule mod_php5.c>
php_value display_errors 1
php_flag register_globals off
</IfModule>
RewriteEngine on
# If know that mod_rewrite is enabled, but you are still getting mod_rewrite errors,
# uncomment the line below and replace "/" with your base directory.
# RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^admin/ - [C]
RewriteRule .* admin/index.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* index.php
# Added this on Jan. 4, 2013 to redirect from old URL to new. Doesn't seem to be working.
RewriteCond %{HTTP_HOST} ^www.aphdigital.org/GVH$
RewriteCond %{HTTP_HOST} ^www\.aphdigital\.org/GVH$
RewriteRule ^gvh/(.*)$ http://gvh.aphdigital.org/$1 [L,QSA,R=301]
# End of Jan. 4 add.
#TEST for redirect added April 3. Also doesn't work.
# To redirect /mysub/foo to http://mysub.mysite.co.uk/foo
#RewriteCond %{HTTP_HOST} ^(www\.)?(aphdigital\.org)$ [NC]
#RewriteRule ^(gvh)/?(.*)$ http://$1.%2/$2 [R=301,L,NC]
#TEST2, code from Stackoverflow question
#Options +FollowSymLinks -MultiViews
#RewriteEngine on
#RewriteBase /
# To redirect http:://www.mysite.co.uk/ to http:://mysite.co.uk/
#RewriteCond %{HTTP_HOST} ^www\.(aphdigital\.org)$ [NC]
#RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]
# To redirect /mysub/foo to http://mysub.mysite.co.uk/foo
#RewriteCond %{HTTP_HOST} ^(www\.)?(aphdigital\.org)$ [NC]
#RewriteRule ^(gvh)/?(.*)$ http://$1.%2/$2 [R=301,L,NC]
#END TEST 2
#Intentionally breaking to see if reading .htaccess. Yep, this breaks it.
#<directory / ></directory>
<FilesMatch "\.(php|ini)$">
Order Allow,Deny
Deny from all
</FilesMatch>
<Files index.php>
Allow from all
</Files>
# Uncomment the lines below in order to enable caching of some files via Apache (after a finished site has gone live)
<IfModule mod_expires.c>
# <FilesMatch "\.(js|ico|gif|jpg|png|css)$">
# ExpiresActive on
# ExpiresDefault "access plus 10 day"
# </FilesMatch>
</IfModule>
This is for a site running the Omeka CMS.
The URL path GVH is not part of %{HTTP_HOST}, so this should be
RewriteCond %{HTTP_HOST} ^(?:www\.)?aphdigital\.org$
RewriteRule ^gvh/(.*)$ http://gvh.aphdigital.org/$1 [R,L,NC]
Never test with 301 enabled, see this answer Tips for debugging .htaccess rewrite rules for details.