I´d like to do some redirects this for a new Wordpress website:
domain.com/index.php?cPath=24 --> domain.com/about/
My .htaccess (root) looks like:
Redirect 301 /index.php?cPath=24 /about/
I get just this:
domain.com/?cPath=24
You can use mod_rewrite with a redirect flag to accomplish this:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^cPath=24
RewriteRule ^ /about/? [R=301,L]
Related
Here is my url:
http://localhost/BA/cookies-policy/register
I want that page to direct to :
http://localhost/BA/register
...and so on if the above link is accessed.
I am not familiar with htaccess.
Try this in .htaccess file in root directory:
RewriteEngine on
RewriteBase /
RewriteRule ^/BA/(.+)$ /$1 [L,QSA]
Basic .htaccess 301 redirect rule for one specific URL:
Redirect 301 /BA/cookies-policy/register http://localhost/BA/register
Rewrite rule to match your needs:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^BA/(.*)$ /$1 [R=301,L]
Try it like below, in your BA directory.
RewriteEngine On
RewriteRule ^cookies-policy/(.+?)$ /BA/$1 [R=301,L]
How can I Rewrite with htaccess file the url
http://www.example.com/index.php?p=1
So it will look like this:
http://www.example.com/index.php
Try adding this :
RewriteEngine On
RewriteRule ^/?index.php$ http://www.example.com/? [L,R=301]
I need the sloution for home page 301 redirection.
If I enter http://www.starmed.dk/index.php in the browse bar, then it will be redirected to http://www.starmed.dk without index.php
Any idea how to do this with an HTACCESS 301 redirect?
Thanks in advance.
//Rewrite to www
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^starmed.dk[nc]
RewriteRule ^(.*)$ http://www.starmed.dk/$1 [r=301,nc]
//301 Redirect Old File
Redirect 301 www.starmed.dk/index.php www.starmed.dk
Edit:
Perhaps your configuration is different. perhaps this:
RewriteRule ^www.starmed.dk/index.php$ www.starmed.dk/ [R=301]
Try the following :
DirectoryIndexRedirect Off
RewriteEngine on
RewriteRule ^index\.php$ / [L,R]
How to redirect this
https://www.example.com/watch?v=ilTNJoSgeF8
to this
http://www.example.com/#/watch/ilTNJoSgeF8
so it just need to change this /watch?v= into this /#/watch/
Using mod_rewrite, you can do something like this in the htaccess file in your document root:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^v=([^&]+)
RewriteRule ^watch$ /#/watch/%1? [L,NE,R]
I have a online store that, for example, is located here: hxxp://domain.com/store/
Within the store directory's .htaccess file I have this:
Options +FollowSymlinks
RewriteEngine on
RewriteBase /store/
RewriteCond %{HTTP_HOST} !^www.domain.com$
RewriteRule ^(.*)$ http://www.domain.com/store/$1 [R=301]
RewriteRule ^/?$ directory.php
RewriteRule ^search/?$ search.php
RewriteRule ^category/([a-zA-Z0-9\!\#\#\$\%\^\&\*\(\)\?\_\-\ ]+)/?$ product.php?CategoryID=$1 [QSA]
RewriteRule ^([a-zA-Z0-9\!\#\#\$\%\^\&\*\(\)\?\_\-\ ]+)/?$ product/detail.php?ProductID=$1 [QSA]
It works great!
My issue (problem) is that I now need to change the /store/ directory to /shop/ which seemed simple enough. However, I need to setup proper 301 redirects so that I don't loose any SE rankings that I may have.
What is the best way to setup 301 redirects in this situation?
The only solution I have found is to setup a redirect 301 for each category, product etc. in the store. Like so, for example.
Redirect 301 /store/category/sample-widgets/ hxxp://www.domain.com/shop/category/sample-widgets/
This works and does what I need it to, but... the URL in the address bar displays like so: hxxp://www.domain.com/shop/category/sample-widgets/?CategoryID=sample-widgets
I can not figure out why or how to remove the query string.
Please help. Thanks.
You can handle the 301 errors by using a PHP script to handle the redirects.
In your .htaccess file you would add this rule:
Redirect 301 /error301.php
Create the file error301.php:
<?php
$redirects = array('/path/to/old/page/' => '/path/to/new/page/',
'/store/category/sample-widgets/' => '/shop/category/sample-widgets/');
if (array_key_exists($_SERVER['REQUEST_URI'], $redirects))
{
$dest = 'http://'.$_SERVER['HTTP_HOST'].$redirects[$_SERVER['REQUEST_URI']];
header("Location: {$dest}", TRUE, 301); // 301 Moved Permanently
}
You could use a simple Redirect directive like:
Redirect 301 /store/ /shop/
Or, if you want to use mod_rewrite as well, you would need to change your current rules as you can not use the base URL /store/ anymore:
RewriteEngine on
RewriteCond %{HTTP_HOST} !=www.example.com
RewriteRule ^ http://www.example.com%{REQUEST_URI} [L,R=301]
RewriteRule ^store/?([^/].*)?$ /shop/$1 [L,R=301]
RewriteRule ^shop/?$ directory.php
RewriteRule ^shop/search/?$ shop/search.php
RewriteRule ^shop/category/([a-zA-Z0-9!##$%^&*()?_\-\ ]+)/?$ product.php?CategoryID=$1 [QSA]
RewriteRule ^shop/([a-zA-Z0-9!##$%^&*()?_\-\ ]+)/?$ product/detail.php?ProductID=$1 [QSA]