htaccess permanent redirect index php to root - .htaccess

I'm using magento and all my urls contains index.php.
Can anyone give me the code to remove index.php
My url looks like this
example.com/index.php/hi-how-are-you.html
I want it redirect to
example.com/hi-how-are-you.html
I want if anyone accessed the page using index.php it should redirect to non index.php url

This has been discussed time and again in the Magento forums, see e.g. this thread.
To redirect visitors from /index.php/path to /path you can use the following mod_rewrite Rule:
RewriteRule ^index.php/(.*) $1 [R=301,QSA,L]
To exclude the admin area, add the following condition before (!) the RewriteRule
RewriteCond %{REQUEST_URI} !^/index.php/admin/
RewriteRule ^index.php/(.*) $1 [R=301,QSA,L]
This tells mod_rewrite not (!) to rewrite if the request begins (^) with /index.php/admin

Related

Redirect specific URL to another URL on another subdomain

I have 5 URLs on a subdomain website http://subdomain.example.com, and I want them to redirect to 5 other URLs on my main website, https://www.example.com/.
Important: URLs do NOT have the same structure!
Example:
http://subdomain.example.com/url1 should redirect to https://www.example.com/ipsum
http://subdomain.example.com/url2 should redirect to https://www.example.com/lorem
etc.
How can I handle that?
UPDATE:
There is a play folder (name of the subdomain) which contains the subdomain website files and a htdocs folder which contains the www website files.
Here is the .htaccess file in my play folder:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Since the subdomain has it's own .htaccess file, you don't need to specify the hostname as part of the redirect. And since you already have mod_rewrite directives in the subdomain's .htaccess file, you should also use mod_rewrite for these redirects (to avoid conflicts). Otherwise, you'll need to specify these redirects one-by-one.
Try the following at the top of your subdomain's /play/.htaccess file. Note that this needs to go before the existing directives in the file.
# Specific redirects
RewriteRule ^url1$ https://www.example.com/ipsum [R=302,L]
RewriteRule ^url2$ https://www.example.com/lorem [R=302,L]
The above would match a request for http://subdomain.example.com/url1 and redirect accordingly, etc.
Note that the RewriteRule pattern (regular expression) does not start with a slash when used in a per-directory (.htaccess) context.
Note that these are 302 (temporary) redirects. Change them to 301 (permanent) - if that is the intention - only once you have confirmed they are working OK (to avoid caching issues).
Try this...
Redirect 301 http://subdomain.example.com/url1 https://www.example.com/ipsum
Redirect 301 http://subdomain.example.com/url2 https://www.example.com/lorem

Rewrite and Redirect with htaccess

A client has asked us to replicate all the content from an old domain (bcsbd.com) to their main domain (ywcacam.org), and also create redirects so the old URLs are still functional. Unfortunately, the URLs aren't exact matches, e.g., [olddomain]/about has become [newdomain]/about_soo_bahk_do. There are less than 10 specific URLs to handle, which we initially did successfully using Redirect statements in the old domain's htaccess file:
# redirect specific pages to page on new domain
Redirect /about http://www.ywcacam.org/about_soo_bahk_do
We also need a catch-all, so that any other requests go to a specific URL on the new domain, e.g., www.bcsbd.com/somefile becomes www.ywcacam.org/soo_bahk_do. We handled this using Rewrite statements:
# catch-all for any requests not specified above
RewriteCond %{HTTP_HOST} ^(bcsbd.com|www.bcsbd.com) [NC]
RewriteRule ^(.*)$ http://www.ywcacam.org/soo_bahk_do [L]
Quick research showed the Rewrite directives (using mod_rewrite) would always be processed before the Redirect directives (using mod_alias). So we replaced the Redirects with Rewrites:
Options +FollowSymlinks
RewriteEngine On
RewriteRule /about http://www.ywcacam.org/about_soo_bahk_do [L]
RewriteRule /programs http://www.ywcacam.org/programs_soo_bahk_do [L]
...
# catch-all for any requests not specified above
RewriteCond %{HTTP_HOST} ^(bcsbd.com|www.bcsbd.com) [NC]
RewriteRule ^(.*)$ http://www.ywcacam.org/soo_bahk_do [L]
The problem is that just the catch-all is working - the new Rewrite rules are being ignored. What are we doing wrong in those statements?
Thanks in advance for the help!

htaccess URL rewrite rule for everything under a folder

I have looked but can't find anything that works. I have an old site that we have updated. They had everything under a folder called site under the root. Now all the customers who have this bookmarked I would like to redirect them, regardless of what is after the folder site (subfolders, files), to the main page of the new site instead of page not found on our new WordPress install. Any help appreciated.
Old URL: http://www.oldsite.com/site/.... to new URL http://www.newsite.com
I have tried this to no avail
Rewrite Rule ^site/(.*)$ http://www.newsite.com
Thanks.
try:
RewriteEngine On
RewriteCond %{HTTP_HOST} oldsite.com$ [NC]
RewriteRule ^site/(.*)$ http://www.newsite.com/$1 [R=301,L]
This redirects something like http://www.oldsite.com/site/some-page.html to http://www.newsite.com/some-page.html (the matching bit of the URI after /site/ gets carried over in the 301 redirect), but if you want to redirect everything for /site/ to the index root of newsite, replace the target in the RewriteRule to http://www.newsite.com/ (remove the $1 bit).
EDIT:
I actually write it wrong above. It is actually the same domain name. The question should read old URL mysite.com/site.... everything under this folder to just redirect to mysite.com
Then what you want is:
RewriteEngine On
RewriteRule ^site/(.*)$ /$1 [R=301,L]
Or alternatively with mod_alias:
RedirectMatch 301 ^/site/(.*)$ /$1
Looks like all you need is this simple 1 liner rule:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^site/ / [R=301,L,NC]

Redirect hundreds of urls with htaccess

hello my url structure right now for the majority of my links is:
www.url.com/category1/sample-keyword.html
I am looking to redirect them to the new url that has dropped the word sample from the url structure ie to this:
www.url.com/category1/keyword.html
what should i put in htaccess that auto redirects all the urls in the www.url.com/category1/ section to redirect to the new url structure?
This should do the trick:
RewriteEngine On
RewriteBase /
RewriteRule ^(.*/)sample-(.*)$ $1$2 [L,R=301]
It will match all URLS with the substring /sample- and strip it from the URL. Depending on your site organization, you may need to adjust the pattern, but that should be a good jumping-off point.
RewriteEngine On
# Redirect sample-*.html to *.html
RewriteRule ^\/?category([0-9]+)\/sample\-([^\/]+)\.html$ http://www.url.com/category$1/$2.html [R=301]
# Serve *.html
RewriteRule ^\/?category([0-9]+)\/([^\/]+)\.html$ page.php?category_id=$1&keyword=$2 [L]

.htaccess 301 redirect path and all child-paths

I want accesses to e.g. www.thisdomain.com/docs/path1/path2 to redirect to www.thatdomain.com/path1/path2
(Note that docs is not a part of the new path)
I have the following on www.thisdomain.com:
RewriteEngine on
RewriteRule ^docs/* http://www.domain.com/ [R=301,L]
If I access www.thisdomain.com/docs, it directs to www.thatdomain.com, but if I access a child-path like www.thisdomain.com/docs/path1/path2 it fails. Is it possible for the redirect to intercept the child-path access and redirect as I need? If so, any pointers?
Thanks.
With regular expressions, * means any number of the previous atom, which will match /docs and /docs/. Try this:
RewriteEngine on
RewriteRule ^docs$ http://www.domain.com/ [R=301,L,QSA]
RewriteRule ^docs/(.*) http://www.domain.com/$1 [R=301,L,QSA]
(QSA is query string append, so /docs/foo?bar=baz won't lose the ?bar=baz.)
According to section "Redirect Old domain to New domain using htaccess redirect" of the first Google result which I found searching for "htaccess redirect" (without the double quotes), this piece of code will suffice:
Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) http://www.newdomain.com/$1 [R=301,L]
According to their description of the technique, it will redirect the directory the .htaccess file is placed in recursively (including any child paths), just as you intend. Of course, mod_rewrite needs to be present for the rewrite directives to work.

Resources