I am trying to force a redirect of all request to
http://website.com/
to
http://website.com/2013/04/
doing this
RewriteEngine on
Options +FollowSymlinks
Options -Multiviews
RewriteRule ^2013/03/ index.html
will direct any request from
website.com/2013/03/ to the index.html
but how do I force the redirect to website.com/2013/03/
To make your URL lovely and suitable for search engine ranking.
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^yoursite.com
RewriteRule (.*) http://www.yoursite.com/$1 [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9} /index.html HTTP/
RewriteRule ^index.html$ http://www.yoursite.com/ [R=301,L]
To redirect
redirect 301 /old-page.php http://www.yoursite.com/new-page.php
Related
I'm trying to redirect all traffic through HTTPS and here's my htaccess file:
<IfModule mod_rewrite.c>
Options +FollowSymLinks -Indexes
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [R=301,L]
RewriteBase /
RedirectMatch 301 /index.php/(.*)$ /$1
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 index.php
</IfModule>
Currently here's what's going on,
If the user types in www.domain.com it redirects to: https://domain.com which is good. I would like help in configuring the file so that if the user also types in domain.com they get redirected to https://domain.com
It would be as simple as updating your pattern:
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [R=301,L]
I am facing some issues with my htaccess. Below is htaccess file I am using. The 301 redirect is working fine but redirects for books isnt working at all.
Another rule at bottom of file ^books.php /books/ [R=301,L] is also working. I am just wondering what is wrong with other rules.
Website is www.gatecounsellor.com
http://www.gatecounsellor.com/books.php is getting redirected according to rule but not this, http://www.gatecounsellor.com/books/aerospace-engineering-ae/
RewriteOptions inherit
Options +FollowSymlinks
Options -Indexes
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^gatecounsellor\.com$ [NC]
RewriteRule ^(.*)$ http://www.gatecounsellor.com/$1 [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^books/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$ /books/display_book_detail.php?branch=$1&subject=$2&title=$3&isbn_13=$4 [NC,L] # Handle product requests
RewriteRule ^books/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$ /books/display_subject_books.php?branch=$1&subject=$2 [NC,L] # Handle product requests
RewriteRule ^books/([A-Za-z0-9-]+)/?$ /books/display_branch_subjects.php?branch=$1 [NC,L] # Handle product requests
RewriteRule ^books.php /books/ [R=301,L]
AddDefaultCharset UTF-8
Any clues what could be wrong in other rules?
Thanks
It could be due to enabling of MultiViews:
Place this line on top of your .htaccess:
Options -MultiViews
UPDATE: Move these 2 rules in /books/.htaccess:
Options +FollowSymlinks -Indexes -MultiViews
RewriteEngine On
RewriteBase /books/
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$ display_book_detail.php?branch=$1&subject=$2&title=$3&isbn_13=$4 [NC,L]
RewriteRule ^([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$ display_subject_books.php?branch=$1&subject=$2 [NC,L]
RewriteRule ^([A-Za-z0-9-]+)/?$ display_branch_subjects.php?branch=$1 [NC,L]
I recently changed my index.html to index.php - I want to be able to do a redirect to reflect this, and then also a rewrite that forces foo.com/index.php to just be foo.com/ and have it access the .php file.
I also have a separate site i.e. bar.com located in a subdirectory under foo.com that I want to remain unaffected.
This is what I had, which results in a redirect loop:
RedirectMatch 301 ^/index.html?$ /index.php
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*index\.php\ HTTP/
RewriteRule ^(.*)index\.php$ /$1 [R=301,L]
Is there a way to do this? Thanks!
The RedirectMatch directive matches after the internal redirect that takes the / request and redirects it to /index.html, then it get put through the URL-file mapping pipeline again and thus matches your redirect directive.
You can try including a:
DirectoryIndex index.php
to prevent this automatic internal redirect. You should also use the %{THE_REQUEST} match with the index.html file like you're doing with index.php:
Options +FollowSymLinks
DirectoryIndex index.php
RewriteEngine on
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*index\.php\ HTTP/
RewriteRule ^(.*)index\.php$ /$1 [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*index\.html\ HTTP/
RewriteRule ^(.*)index\.html$ /$1index.php [R=301,L]
Or you can bypass index.php entirely:
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*index\.html\ HTTP/
RewriteRule ^(.*)index\.html$ /$1 [R=301,L]
i'm using the following code to force non www URLs to redirect to www URLs;
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
</IfModule>
<IfModule mod_rewrite.c>
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} !^www\..+$ [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
</IfModule>
However, when I visit mydomain.com it does not redirect to www.mydomain.com.
I'm using Red Hat Linux and wondering if there is anything else I need to add to the htaccess to get this to work?
Thanks.
Change your rewrite rule as follows:
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NC,QSA]
I need to pass through a list of pages to show them coming from subdomain
When a user enters this url in the browser
xyz.mydomain.com/
it should be passed though as
www.mydomain.com/level1/pageA?subdomain=xyz
and
xyz.mydomain.com/innerpage_abc?param1=123
as
www.mydomain.com/level1/innerpage?dynamicparam=abc¶m1=123&subdomain=xyz
Enable mod_rewrite and mod_proxy. Then put this code in .htaccess under DOCUMENT_ROOT:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(xyz)\.mydomain\.com$ [NC]
RewriteRule ^$ http://www.mydomain.com/level1/pageA?subdomain=%1 [L,P,QSA]
RewriteCond %{HTTP_HOST} ^(xyz)\.mydomain\.com$ [NC]
RewriteCond %{QUERY_STRING} (?:^|&)param1=([^&]+) [NC]
RewriteRule ^([^_]+)_([^/]+)/?$ http://www.mydomain.com/level1/$1?dynamicparam=$2&subdomain=%1 [NC,L,P,QSA]