Show url of index page with .htaccess - .htaccess

I have googled around and can't find an answer to my question so her I am. How can I force, with .htaccess, the filename of the index page to show when accessed by just the domain.
So if http://example.com is typed in http://examples.com/home will show in the address bar.
I have already used .htaccess to set home.php as the index page and remove the .php extension.
current .htaccess
DirectoryIndex home.php
RewriteEngine on
#add php extension
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteCond %{REQUEST_URI} !^/(phpscripts|js)/ [NC]
RewriteRule ^([^/]*)(?:/(.*?|))?/?$ /$1.php?$2 [L]
# redirect to .php-less link if requested directly
RewriteCond %{THE_REQUEST} ^[A-Z]+\s.+\.php\sHTTP/.+
RewriteCond %{REQUEST_URI} !^/(phpscripts|js)/ [NC]
RewriteRule ^(.*)\.php /$1 [R=301,L]
#redirect www to non-www
RewriteCond %{HTTP_HOST} ^www\.^([a-zA-Z0-9_-]+)$ [NC]
RewriteRule ^(.*)$ http://^([a-zA-Z0-9_-]+)$1 [L,R=301]
#remove trailing slash
RewriteRule ^(.*)/$ /$1 [L,R=301]

You want
RewriteRule ^$ /home [L,R=301]
This should catch both http://example.com and http://example.com/, and send them to http://example.com/home

Related

htaccess RewriteRule and Redirect 301 interfering with one another

My .htaccess file includes this, which allows the URL structure in my ExpressionEngine site to function:
RewriteRule ^(.*)$ /index.php?/$1 [L]
However, it is interfering with what I'm trying to do here, redirecting an old page:
Redirect 301 /old-url/ /
This is what I see in my browser address after I load the /old-url/ address:
https://www.domain.test/?/old-url/
If I take out the RewriteRule, my Redirect 301 works, but all the navigation in the site breaks. Is there some way for me to make an exception where I want to redirect old URLs? I have inherited someone else's work in this case.
Edit: here is my entire .htaccess file content:
RewriteEngine On
Redirect 301 /in-loving-memory-of-our-partners /
Redirect 301 /in-loving-memory-of-our-partners/ /
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R,L]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteRule ^sitemap\.xml$ /sitemap/xml [NC,L]
RewriteCond $1 !^(assets|emergency|portalimages|images|system|themes|test|AUL|swfs|favicon\.ico|robots\.txt|index\.php) [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteRule ^(.well-known) - [L]

I cant redirect to other domain without change url

im trying to redirect my subfolder to other domain and i want that work without changing the url
the code about htaccess inside /folder is:
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/
RewriteRule ^(.*) http://domain2.com/$1 [P]
this redirect to the second domain but the url changed..
could it be a conflict with the htacces in the root?
root htaccess:
RewriteEngine on
# Remove ".php" from urls
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
# Redirect to https version
RewriteCond %{HTTP:X-Forwarded-Proto} =http [OR]
RewriteCond %{HTTP:X-Forwarded-Proto} =""
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
#indexies
Options -Indexes
DirectoryIndex home.php
im new with htaccess but it all seems correct..

Catch all redirect

This is the htaccess file. I'm wanting to add a catch-all 301 redirect RewriteRule.
This is not working. Any ideas?
RewriteRule ^/(.*)$1 http://www.domain.co.uk/ [R=301,L]
Here are the rest of the rewrites.
enter coOptions +SymlinksIfOwnerMatch +MultiViews
RewriteEngine On
RewriteBase /
### HTTP > HTTPS & non WWW to WWW version
# RewriteCond %{HTTPS} !on [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
# RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(\S*)\sHTTP [NC]
RewriteRule ^ http://www.domain.co.uk/%1 [NE,L,R=301]
### index.php & index to root domain
RewriteRule ^index(?:\.php)? http://www.domain.co.uk/ [R=301,L]
### special rewrite rules for shortened urls ##
RewriteRule ^section(?:\.php)?/(.*)$ /s/$1 [R=301,L]
### To remove section page if 1 which is default for most (unless products span more)
RewriteRule ^s\.php/(.*)/1/(.*) /s/$1/$2 [R=301,L]
RewriteRule ^product(?:\.php)?/(.*)$ /p/$1 [R=301,L]
RewriteRule ^article(?:\.php)?/(.*)$ /a/$1 [R=301,L]
RewriteRule ^discount(?:\.php)/(.*)$ /d/$1 [R=301,L]
### Core Jshop .php removal
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*?)\.php/(.*)$ $1.php?$2 [L,QSA]de here
Redirect 301 /blog http://www.domain.co.uk/a/8/nursing-home-news/
RewriteRule ^/(.*)$1 http://www.domain.co.uk/ [R=301,L]
If your rewrite rules are in an htaccess file then you need to remove the leading slash from your rule's pattern as RewriteRule's regex matches against a relative old path starting without a / .
Try :
RewriteRule ^(.*)$ http://www.domain.co.uk/ [R=301,L]
Make sure to clear your browser cache before testing this.

Redirect conflicting with RewriteRule, what may be causing it?

I am currently switching from olddomain.com into newdomain.com and at the top of my .htaccess I have the following Redirect's:
Redirect 301 /pageA/ http://newsite.com/pageA
Redirect 301 /pageB/ http://newsite.com/pageB
Redirect 301 /pageCa/ http://newsite.com/pageCb
Redirect 301 /pageD/ http://newsite.com/pageD
As you can see there, one of the redirects, "pageCa" changes to "pageCb" and sometimes the 301's take precedence. If I later type the same URL it acts as if the 301's aren't there and the below catch all takes effect instead.
# Catch all for pages different from the Redirects
RewriteCond %{HTTP_HOST} ^oldsite.com [NC,OR]
RewriteCond %{HTTP_HOST} ^www.oldsite.com [NC]
RewriteRule ^(.*)$ http://newsite.com/$1 [L,R=301,NC]
What may be causing this conflict?
Both domains are under the same DocumentRoot and everything else seems to work reliably.
My full .htaccess:
AddHandler application/x-httpd-php54s .php
Redirect 301 /pageA/ http://newsite.com/pageA
Redirect 301 /pageB/ http://newsite.com/pageB
Redirect 301 /pageCa/ http://newsite.com/pageCb
Redirect 301 /pageD/ http://newsite.com/pageD
ErrorDocument 404 /404
<IfModule mod_rewrite.c>
RewriteEngine On
Options +SymLinksIfOwnerMatch
# Removes www
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]
# Catch all for pages different from the Redirects
RewriteCond %{HTTP_HOST} ^oldsite.com [NC,OR]
RewriteCond %{HTTP_HOST} ^www.oldsite.com [NC]
RewriteRule ^(.*)$ http://newsite.com/$1 [L,R=301,NC]
# Unless directory, remove trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/$ http://newsite.com/$1 [R=301,L]
# Redirect external .php requests to extensionless url
RewriteCond %{THE_REQUEST} ^(.+)\.php([#?][^\ ]*)?\ HTTP/
RewriteRule ^(.+)\.php$ http://newsite.com/$1 [R=301,L]
# Maps to php files
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^\.]+)$ $1.php [NC]
# All 404 requests
RewriteCond %{REQUEST_URI} ^/404$
RewriteRule ^(.*)$ http://newsite.com/404 [L]
</IfModule>
Ok it seems to be working with the following before the "catch all" instead of the redirects:
Where the page name stays the same, url changing:
RewriteRule ^oldsite.com/pageA/?$ http://newsite.com/pageA [L]
Where both are different:
RewriteRule ^pageCa/?$ http://newsite.com/pageCb [L]
Thanks

htaccess redirect from domain.com/index.php?page=about to domain.com/about

I've upgraded an old website and wanted to redirect all the old pages to the new ones. the old website used the index page and a query string to server the relevant content.
here is the new htaccess file. the problem in question is getting the redirect to work. also if you can steamline this file:
Options +FollowSymLinks
Options +Indexes
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^www.domain.co.uk$ [NC]
RewriteRule ^(.*)$ http://domain.co.uk/$1 [R=301,L]
#if its not a directory
RewriteCond %{REQUEST_FILENAME} !-d
#and it has a trailing slash then redirect to URL without slash
RewriteRule ^(.+)/$ /$1 [L,R=301]
#this removes php extention
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
# stops you accessing url with.php
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /([^.?\ ]+)\.php
RewriteRule ^([^.]+)\.php(/.+)?$ /$1%{PATH_INFO} [R=301]
RewriteRule ^news/([^/]*)/([^/]*)$ /news?id=$1&title=$2 [L]
Redirect 301 index?page=about http://domain.co.uk/about
ErrorDocument 404 http://domain.co.uk/404
The apropiate rule to redirect domain.com/index.php?page=about to domain.com/about is the following
RewriteRule ^index\.php$ %{QUERY_STRING} [C]
RewriteRule page=(.*) /$1? [R=301,L]

Resources