In my htaccess file I have the following redirections:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain.com
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]
RewriteRule index.html$ Controller/index.php [L]
</IfModule>
I want index.html (which does not exist) to be redirected to my controller.
index.php (which exists) should be my home page.
Now, my homepage is not working when typing http://www.domain.com/ in my browser. That URL redirects to my controller.
http://www.domain.com/index.php works fine, bringing my homepage.
How do I set index.php as my index file keeping my redirection for the controller?
If I've understood your situation correctly, you just want to specify DirectoryIndex in your .htaccess file so that it only points to index.php:
DirectoryIndex index.php
Between that and your rules, that leads to the following URL to file mappings:
http://www.example.com/ -> /index.php
http://www.example.com/index.php -> /index.php
http://www.example.com/index.html -> /Controller/index.php
Related
My url looks like -
http://localhost/user_notes/?id=1234.
I want to be turn it into user friendly url like
http://localhost/user_notes/1234
My .htaccess file looks like -
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ public/ [L]
RewriteRule (.*) public/$1 [L]
RewriteRule ^(.+)$ /user_notes/?id=$1
</IfModule>
The problem is with RewriteRule ^(.+)$ /user_notes/?id=$1
For more info see my directory structure
Note : In my directory structure there is also a public folder. But I can access files without including public in URL through htaccess file (line 3).
Could you please place these rules at top of your htaccess file(I hope there are NO redirect rules for https in your htaccess file). Please make sure to clear your browser cache before testing your URLs.
RewriteEngine ON
RewriteRule ^ public%{REQUEST_URI} [L]
RewriteRule ^(user_notes)/(.*)/?$ $1/?id=$2 [NC,L]
I know this has been asked so many times before but I coulnd't find this particular script.
So I've started a franchise, and I've moved my www.site.com to shop1.site.com (shop2.site.com also exists.)
Google seems confused by the new setup so this is what I need
If someone goes to a url containing a directory after the trailing slash, I need to redirected to the new site with a 301
If not, leave it be
For example:
www.site.com/info/ -> shop1.site.com/info/
www.site.com/help/ -> shop1.site.com/help/
www.site.com (leave as is)
So basically any url with a directory, redirect, otherwise leave it be
Update
here is my current htaccess
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
ErrorDocument 404 /index.php
ErrorDocument 500 /index.php
This is what I needed. This redirects every page except for the root. Be warned, this also redirect's all traffic to HTTP and not HTTPS
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
#Rewrite everything except root
RewriteCond %{HTTP_HOST} ^(www\.)?site\.com$ [NC]
RewriteRule ^.+$ http://shop1.site.com%{REQUEST_URI} [L,R=301]
I have a CakePHP app that has some html static files in webroot.
HTML files are in some directories like webroot/dir1/dir2/page.html.
When I enter url: site.com/dir1 I get redirected to site.com/webroot/dir1/ but when I enter site.com/dir1/ I get redirected to the first page site.com
And If I enter url for the html file: site.com/dir1/dir2/page.html I get redirected to the first page site.com. It supposed to show the html file. How can I make it show html file and not redirect to first page?
In my public_html the htaccess is:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
In the webroot the htaccess is:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
It's definitely not connected to CakePHP. Just ignore your directory / ies that should not be processed by CakePHP's routing system, see this related SO post.
Insert .htaccess into your directory/ies that should be ignored:
RewriteEngine Off
your questions isn't about php,
it's about the apache Webserver or more about -> Apache Module mod_rewrite
Rewrite Engine is only called one time, so you have to put all changes in one File.
kind regards
set
I want to redirect several pages to a PHP page with GET variables. However, when I try to use an .htaccess file, it redirects but changes the URL. I don't want it to change the URL structure when redirecting. How would I do this?
For example, I want to redirect /fly-snooze-cruise to http://example.com/package_listing.php?package-type=fly-snooze-cruise
and /fly-snooze-cruise/orlando-airport to http://example.com/package_listing.php?package-type=fly-snooze-cruise&airport=orlando-airport
Here is my .htaccess code:
Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteRule ^fly-snooze-cruise$ http://www.example.com/package_listing.php?package-type=fly-snooze-cruise [L]
RewriteRule ^fly-snooze-cruise/orlando-airport$ http://www.example.com/package_listing.php?package-type=fly-snooze-cruise&airport=orlando-airport [L]
RewriteRule ^fly-snooze-cruise/orlando-sanford-airport$ http://www.example.com/package_listing.php?package-type=fly-snooze-cruise&airport=orlando-sanford-airport [L]
RewriteRule ^fly-snooze-cruise/melbourne-airport$ http://www.example.com/package_listing.php?package-type=fly-snooze-cruise&airport=melbourne-airport [L]
RewriteRule ^snooze-park-cruise$ http://www.example.com/package_listing.php?package-type=snooze-park-cruise [L]
I have a url like:
http://x.x.x.x/~mmi/
which maps to the public_html folder on my site. I have installed cakephp on my site. The default htaccess file for cakephp looks like below:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
I want to be redirected to:
http://x.x.x.x/~mmi/app/webroot/
instead of :
http://x.x.x.x/app/webroot/~mmi/
which is happening now. How should i modify htaccess file to get this desired result?
Following does the trick:
RewriteEngine on
RewriteRule ^~mmi/(.*)$ http://x.x.x.x/~mmi/app/webroot/$1