Redirect many old asp pages in htaccess - .htaccess

I have converted a site from .asp to .php pages
now I need to redirect many old .asp pages to the home page
the structure of the .asp URLs is:
/dettagli.asp?ID=123456789
I would like any /dettagli.asp page to be redirected to the home page, regardless of the parameter which is passed (these ages no longer exist...)
I have tried some regex so far but no luck....

You can use this rule as your very first rule:
RewriteEngine On
RewriteRule ^dettagli\.asp$ /? [L,R=302]

Solved.
I simply was using rules AFTER Joomla Rules that were applied BEFORE mine...

Related

Opencart dont redirect not found links

I migrated my e-commerce site oscommerce to open-cart and my old links coming to the open-cart site. whenever old links requested open-cart redirects to the homepage if the pattern is like this .../index.php?manufacturers_id=...
I changed .htacess file to exclude redirect to the homepage by defining these lines
RewriteCond %{REQUEST_URI} manufacturers_id
RewriteRule .* NOT.php
if requested url contains manufacturers_id "it will" redirect to NOT.php instead homepage. But these .htaccess definitions don't work
I also want to cancel 404 pages I prefer to use the server default error page.
How can I make this? Thank you

htaccess redirect files with the same name to just one file (been hacked)

I would like your help to modify my .htaccess file. My site has been hacked and the malware has created thousands of pages and has really hurt my rankings. I have deleted the pages, but I want all of those links to redirect to one 404 page.
What do I need to write in .htaccess in order to redirect all of the pages that contain a certain word?
I have tried this
RewriteCond %{QUERY_STRING} ^(theword)
RewriteRule ^$ https://example.com/404.php [R=301,L]
But it doesn't seem to work: the 404 page I created appears, but the link still remains in the browser, just that now it's like this
http://example.com/404.php?theword=blablabla
Maybe because my site is on a wordpress platform?
I want all the pages that start with ?theword= to be redirected entirely and for the new link to appear /404.php not /404.php?theword=
Thank you in advance for your help!
The [QSD] (query string discard) flag added to your RewriteRule will drop the query string.

.htaccess redirect from mysite.com/ to mysite.com/index.php/folder

I have a mirrored site and I need all the visitors to be redirected to a certain page other than the original homepage. But the original site (not the mirror) should continue to behave without changes. Therefore, I need to include a redirect rule in my .htaccess based on the referrer. If the visitor targets the mirrored site, I need to redirect. If the visitor lands at the original site, nothing should be done.
How do I implement this?
If you have the following setup:
fancysite.com - your main site with all the pages
coolname.com - a site that should redirect all requests to your main site
For example, a user requesting www.coolname.com/infos/january.html should be redirected to www.fancysite.com/infos/january.html.
This redirect should be done with a 301 HTTP response (moved permanently) for several reasons, e.g. google preferring it.
To do this on an Apache server, you put a .htaccess file in the root directory of your website (may differ from the root of your account). The server must have the module mod_rewrite and you must have the rights to use it.
Put the following in your .htaccess to redirect all requests, as you do not want to update it for every new page you put on your site:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !fancysite.com$ [NC]
RewriteRule ^(.*)$ http://www.fancysite.com/$1 [L,R=301]
The module mod_rewrite is very powerful, have a look at the documentation, if you have the time:
http://httpd.apache.org/docs/current/mod/mod_rewrite.html

.htaccess 301 re-directing .html pages to sitemap.html

I've tried 301 redirecting .html pages to sitemap.html in two ways and neither one works.
I've checked this code over and over again.
I've used .htaccess checkers/validators and they show no errors.
The same code works for folder-to-folder re-directs--this only happens for re-directs from .html files to sitemap.html.
The Problem:
The pages should be redirected to www.example.com/sitemap.html
Instead they're redirected to www.example.com/sitemap.htmlpage.html
In other words, .htaccess somehow puts the file name after sitemap.html.
I've used these two methods:
1:
RewriteRule ^directory/(.*)$ /sitemap.html$1 [R=301,NC,L]
In the first one, all the files within the directory should be re-directed to sitemap.html. Note that the index page of the category re-directs fine but the .html ending pages inside it don't.
2:
redirect 301 /directory/page.html http://www.example.com/sitemap.html
I've also tried redirecting each page individually with the same results.
Any idea what's wrong here?
You should not use captured for redirecting everything to /sitemap.xml. Just use a rule like this in root .htaccess:
RewriteEngine On
RewriteRule ^directory/ /sitemap.html [R=301,NC,L]

htaccess redirect .asp page but allow same page with variables to serve

using htaccess (isapi) I need to redirect .asp page but leave .asp page WITH variables untouched. This sounds simple and so I thought it was but my efforts have been fruitless.
RewriteRule ^CodePage.asp$ ^NewCodePage.asp? [R=301,NC,L]
I want to match EXPLICITLY that exact URL to the new Root Landing page but leave all dynamic pages served from CodePage.asp untouched.
e.g. http://www.domain.com/CodePage.asp?prodid=666
I thought the '$' sign would achieve this but the rule is matching ALL full path dynamic pages as well and pushing them to the NewCodePage.asp page. Note, I do not want to pass the variables to the new page, just the root landing page.
Thank you!
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^CodePage\.asp$ NewCodePage.asp [R=301,NC]

Resources