How can I redirect my www.domain.com to www.domain.com/home using htaccess?
I already have an existing htaccess file which handles my MVC.
I have the following htaccess file:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]`
TIA
just put this line below:
RewriteRule ^ /home [L]
I am assuming that /home is either an directory or having other rewriterule for it.
I got it to work by adding these lines of code
RewriteCond %{HTTP_HOST} ^domain\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.domain\.com$
RewriteRule ^/?$ "https\:\/\/www\.domain\.com\/home" [R=301,L]
Thanks for the help :)
Related
I am trying to rewrite a subdomain sub.example.com to example.com/works/sub. I have the following in my htaccess file, but its not working. Please help.
RewriteCond %{HTTP_HOST} !^www
RewriteCond %{HTTP_HOST} ^(.*).example.com
RewriteRule ^/(.*)$ http://example.com/%1/$1 [L,NC,P]
If have also tried the following:
RewriteCond %{HTTP_HOST} ^sub\.example\.com
RewriteRule ^(.*)$ http://example.com/works/sub/$1 [L,NC,QSA]
In both cases, I get ERR_NAME_NOT_RESOLVED whenever I try to navigate to the page.
The funny thing is that every other rule in the htaccess file works. Including the rule that follows it immediately:
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
Just that first part is not working.
I want create redirect in my htaccess file. From url with index.php to page without index.php, but only for one specific folder "catalog".
For example:
from /catalog/some_folder/index.php to /catalog/some_folder/ or
from /catalog/some_folder/etc/index.php to /catalog/some_folder/etc/
URL like this /catalog2/some_folder/index.php don't must redirect
I try add those lines(localhost because it was xampp):
RewriteCond %{REQUEST_URI} /catalog/+[^\.]+index.php$
RewriteRule ^index\.php$ localhost/$1 [R=301,L]
But this didn't work. How can i force this to work right?
You can use this rule in root .htaccess:
# remove index.php
RewriteCond %{THE_REQUEST} /index\.php [NC]
RewriteRule ^(catalog/.+)index\.php$ /$1 [L,R=302,NC,NE]
RewriteCond %{REQUEST_URI} /index.php
RewriteRule ^(.*)index\.(php)$ https://%{SERVER_NAME}/$1 [R=301,L]
If you need to remove all "index.php" at the end of the address
To remove index.php:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]
Remember,you will need to activate mod_rewrite.
RewriteEngine On
RewriteCond %{THE_REQUEST} (?:/[^/]*)*/index\.php[?#\ ]
RewriteRule .* %{REQUEST_URI}/../ [L,R=301]
For me this is working the solution above is sending me to a folder up one level.
I'm basics to htaccess. I have an issue with htacess SEO Friendly URL.
For Ex:
If the URL is like www.example.com/A then htaccess should redirect to browse-category.php?alphabet=$1
My Code, but not working:
RewriteCond %{REQUEST_URI} [a-zA-Z]{1}$
RewriteRule ^([a-zA-Z0-9-/]+)$ browse-category.php?alphabet=$1
If URL is like this www.example.com/add-business then it should redirect to $1.php.
Please help me and thanks in advance
You can use this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteBase /
# if a matching .php file exists then internally forward /file to /file.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f [NC]
RewriteRule ^(.+?)/?$ /$1.php [L]
# otherwise forward to browse-category.php?alphabet=$1
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ browse-category.php?alphabet=$1 [L,QSA]
I am through .htaccess redirecting my domain to a subfolder in my public_html folder like this:
DirectoryIndex index.php
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?mydomain.com$
RewriteCond %{REQUEST_URI} !^/mydomain.com/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /mydomain.com/$1
RewriteCond %{HTTP_HOST} ^(www.)?mydomain.com$
RewriteRule ^(/)?$ mydomain.com/php [L]
When writing mydomain.com/index.php everything just works fine but if i leave out the index.php and just writes mydomain.co I get an 404 error?!?
What am i missing?
Any help is appreciated and thanks in advance :-)
Change the ^(.*)$ pattern to ^(.+)$.
Or, switch the order of your rules.
Have you tried removing the trailing slash from
RewriteCond %{REQUEST_URI} !^/mydomain.com/
To make it
RewriteCond %{REQUEST_URI} !^/mydomain.com
?
I'm trying to force www on my website using a RewriteRule in the htaccess file.
I'm using FuelPHP and I have to have the following rewrite rule in the htaccess file but the methods I found to force www didn't play nice with my current setup.
Current htaccess code
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
Code that I found here to force www
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
How can I combine these to enable forcing www and still have the other rule in the htacess file?
Try using this:
RewriteEngine on
RewriteBase /
# Redirect to wwww
RewriteCond %{HTTP_HOST} !^www\.yourdomain\.com
RewriteRule (.*) http://www.yourdomain.com/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
FuelPHP comes with a .htaccess file in the public folder that contains a rewrite example for this situation.