htaccess rewrite all with document_general_info in the url - .htaccess

I need to be able to rewrite all urls that have document_general_info in the url.
Example urls would be like:
www.mysite.com/index.php?main_page=document_general_info&cPath=2371_2377_2407_2606&products_id=27990
www.mysite.com/index.php?main_page=document_general_info&cPath=2371_2373&products_id=23055
I need to redirect them to index.php as they are historical links for content that no longer exists and will give me over 3000 404 errors
Thanks

Try this :
RewriteEngine on
RewriteCond %{THE_REQUEST} \?.*document_general_info [NC]
RewriteRule ^ /index.php? [L,R]
Change R to R=301 (Permanent redirect) when you are sure the rule is working ok.

Related

Dynamic url's redirect from old to new url's using .htaccess

I want to redirect below two dynamic url from old url's to new url's using .htaccess and i have done this application using codeigniter.
1) This are the dynamic url's and there are more than thousands of url's in my database.
Old(From) URL
https://www.example.com/area-name/pangothe-263001
New(To) URL
https://www.example.com/pangothe-263001
2) This are the amp version of the above url.
Old(From) URL
https://www.example.com/amp-area-name/pangothe-263001
New(To) URL
https://www.example.com/pangothe-263001/amp
I have tried with below code
RewriteRule ^area-name$ http://www.example.com/area-name [R=301,L]
RewriteRule ^amp-area-name$ http://www.example.com/amp-area-name [R=301,L]
But not redirecting to the new urls. How can do this redirect using .htaccess.
Keep these 2 redirect rules just below RewriteEngine line:
RewriteEngine On
RewriteRule ^area-name/(.+)$ /$1 [R=301,L,NC,NE]
RewriteRule ^amp-area-name/(.+)$ /$1/amp [R=301,L,NC,NE]
# remaining rules go below this
Try This
RewriteRule ^area-name/pangothe-263001/?$ $1/pangothe-263001$2 [R=301,L]
Try with below rules,
Canonical links Redirect
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/area-name/(.*)$
AMP links Redirect
RewriteRule ^ https://www.example.com/%1 [R=301]
RewriteCond %{REQUEST_URI} ^/amp-area-name/(.*)$
RewriteRule ^ https://www.example.com/%1/amp [R=301]

htaccess 301 redirect for non friendly urls

I'm having trouble finding something to work to this problem.
I have a rewrite rule in my htaccess that does the rewrite for the url when I acces it directly :
RewriteRule [a-zA-Z0-9_]+-c([0-9]+)-p([0-9]+)$ list.php?id=$1&page=$2 [QSA]
So www.domain.com/list-of-products-c1-p1 works fine.
But so does www.domain.com/list.php?id=1&page=1 which I don't want!
is there any way to 301 redirect this unfriendly url to the seo-friendly url with htaccess?
Thanx!
Try below rule,
RewriteCond %{REQUEST_FILENAME}\.php -f [OR]
RewriteCond %{QUERY_STRING} ^id=([\d]+)&page=([\d]+)$
RewriteRule ^ list-of-products-c%1-p%2 [R=301,L]

Redirect link with parameters using htaccess

I want to redirect this link:
/content/catagorie.php?item=Notariaat
To this link:
http://www.meddo.nl/vacatures/notariaat/
I used this:
Redirect /content/catagorie.php?item=Notariaat http://www.meddo.nl/vacatures/notariaat/
But it didn't work.
Thx
use this 301 redirect
Redirect 301 http://example.com/content/catagorie.php?item=Notariaat http://www.meddo.nl/vacatures/notariaat/
You can use these 2 rules in root .htaccess file:
RewriteEngine On
# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} /content/catagorie\.php\?item=([^\s&]+) [NC]
RewriteRule ^ /vacatures/%1? [R=302,L,NE]
# internal forward from pretty URL to actual one
RewriteRule ^vacatures/([^/.]+)/?$ /content/catagorie.php\?item=$1 [L,QSA,NC]

Rewrite, Redirect, and avoid duplicate content

I'm trying to redirect a single page using .htaccess. The actual file is /abc.php, I want it to appear as /abc. So these are my pseudo-rules:
if the user hits /abc.php, rewrite the url as /abc
if the user hits /abc, serve /abc.php
For SEO purposes, only one of /abc and /abc.php should be available.
My naive approach is this:
Redirect 301 /abc.php /abc
RewriteRule ^abcs$ /abc.php [NC,L]
This is causing infinite, looping redirects. How do I do this correctly?
You can use this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteBase /
# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} \s/+(abc)\.php[\s?] [NC]
RewriteRule ^ %1? [R=302,L]
# internal forward from pretty URL to actual one
RewriteRule ^(abc)/?$ $1.php [L,NC]

.htaccess and redirect urls

I have used the following to rewrite urls on my website
RewriteRule writers/(.*)/ writer-pages.php?page_name=$1
RewriteRule writers/(.*) writer-pages.php?page_name=$1
which works fine, but I have old pages that have an extension /writers/name-here.php and the rewrite above removes the .php how can I redirect the old .php to the the urls without the extension.
Another problem is I don't want redirect all .php pages
Any idea how I can do this. Any help would be much appreciated
RewriteRule writers/(.*).php writers/$1/
you can test your rewrite rules at rewrite-rule-tester
Your 2 rules can be combined into one.
You need an additional rule.
Here is the code:
# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} /+writer-pages\.php\?page_name=([^\s&]+) [NC]
RewriteRule ^ writers/%1? [R=302,L]
# your original rule
RewriteRule writers/([^/]*)/?$ writer-pages.php?page_name=$1 [L,QSA]

Resources