Mod_Rewrite link to external url without parameters - php

i changed my cms and have now some old urls, that are still linked by other websites.
Now i have to redirect the old links to my new sites Start Page.
The old CMS was installed in a subfolder named "contentms". The new CMS is installed in the root-folder.
Old Urls look like: mywebsite.com/contentms/content.php?idcat=62
When i try to forward it using my rewrite rule:
RewriteEngine on
RewriteRule ^contentms/.*$ http://www.mywebsite.com/ [R=301,L]
It works, but there will appear:
http://www.mywebsite.com/?idcat=62
But i want to have only http://www.mywebsite.com, without the "?idcat=62" added to the external url.
Maybe you have a solution for me.
Thanks!

Give this a try and see how it works for you.
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/contentms
RewriteRule ^(.*) http://www.mywebsite.com/? [R=301,L]
You can do this in the same line.
RewriteEngine on
RewriteRule ^contentms/.*$ http://www.mywebsite.com/? [R=301,L]

Related

RewriteCond %{QUERY_STRING} for new site

I have a really old Joomla-1.0 site with tens of thousands of articles that we recently upgraded to a current version of Joomla with SEF. This is on apache-2.4.34 on fedora29.
The problem is that it doesn't support the old URL format any longer, so I'm trying to rewrite many of the old URL formats to work with the site.
The one I'm having the most difficulty with contains a query string:
example.com/index.php?option=login
This should redirect to example.com/register
My rewrite rules are not working, however:
# /index.php?option=login
RewriteEngine on
RewriteCond %{QUERY_STRING} ^option=login$
RewriteRule ^/index.php$ https://linuxsecurity.com/register [R=301,L,QSD]
This is placed in the .htaccess file in the document root. I've also tried placing it in a section within the virtual domain config.
It appears it's being ignored entirely. It reports an error like "Component not found", as if it's being interpreted by joomla.
I also have several other RewriteRule entries below that don't appear to work. They just report 404 pages. If I enter the article IDs into the replacement link, it works fine.
RewriteRule ^/content/view/([^/]+) /index.php?option=com_content&view=article&id=$1 [R=301,L]
I'd appreciate any advice you may be able to provide.
Your condition is good, but need to tweak the rule for the login one. Please try:
RewriteEngine on
RewriteCond %{QUERY_STRING} ^option=login$
RewriteRule ^(.*) https://linuxsecurity.com/register [R=301,L,QSD]
For the other content redirects, this is what I have used for Joomla 1.0 to Joomla 3.x before:
RewriteRule ^content/view/(.*)$ /index.php?option=com_content&view=article&id=$1 [L,R=301]
https://www.yellowwebmonkey.com/developer-blog/item/redirect-joomla-1-0-sef-links-for-joomla-3-x

Setting up specific page redirects as well as entire site redirects in .htaccess

I want to setup a redirect on my site to go to a different domain which I am able to do so with this rewrite rule:
RewriteEngine on
RewriteRule ^(.*)$ https://www.newdomain.com/$1 [R=301,L]
This works great but there are also a few pages that I want to completely change the url as well as redirect to the new domain. Here is an example:
1.) Here is an example url to my old domain. https://www.olddomain.com/product-tag/[tag-name]/. I want this go to https://www.newdomain.com/parts?category=[tag-name]/.
2.) Here is an example url to my old domain. https://www.olddomain.com/product-categories/[category-name]/garbage. I want this go to https://www.newdomain.com/parts?category=[category-name]/.
I was hoping that adding something like this would do the trick but it does not seem to be working:
RewriteEngine on
RewriteRule ^/product-tag/(.*)$ https://www.newdomain.com/parts?category=$1 [R=301,L]
RewriteRule ^(.*)$ https://www.newdomain.com/$1 [R=301,L]
How can I achieve this?
Have it like this:
RewriteEngine on
# handle both specific URL redirects
RewriteRule ^/?product-(?:tag|categories)/([\w-]+) https://www.newdomain.com/parts?category=$1 [R=301,L,NC,QSA]
# redirect everything else
RewriteRule ^(.*)$ https://www.newdomain.com/$1 [R=301,L,NE]

.htaccess dynamic url (old site) to static url in magento

Long time reader first time poster.
I have read through what feels like 100's on similar posts trying to make it fit what i am trying to do.
Apologies if its been covered. I believe I have the correct code but it maybe conflicting with something else?
I have old URLs from an old ASP cart and want to 301 redirect to new magneto static pages.
There are only 5 of these URLS so don't need a bulk action.
example:
OLD URL: http://test.com.au/shopcontent.asp?type=FAQ%20and%20Terms
NEW URL: http://test.com.au/privacy-policy-cookie-restriction-mode
I know that from reading other posts you can not simply use:
Redirect 301 /shopcontent.asp?type=FAQ%20and%20Terms /privacy-policy-cookie-restriction-mode
So I have worked out that this should work:
RewriteCond %{QUERY_STRING} ^type=FAQ%20and%20Terms$ [NC]
RewriteRule ^shopcontent\.asp$ /privacy-policy-cookie-restriction-mode/? [NC,R=301,L]
I have also tried removing the %20 for the spaces like this:
RewriteCond %{QUERY_STRING} ^type=FAQ\ and\ Terms$ [NC]
RewriteRule ^shopcontent\.asp$ /privacy-policy-cookie-restriction-mode/? [NC,R=301,L]
When I try and access the old URL it just goes to the 404 page. I am using standard .htaccess file that came with Magento (I can post if that helps);
I am using a VPS which mod rewrite is enabled. I have other Redirect 301's for non dynamic URLS.
Are there any logs that I can look at?
Appreciate any help or advice.
Thanks Rudi
ps. I found this post which got me to where i am now
RewriteCond %{QUERY_STRING} in mod_rewrite (dynamic to static URL) not working
You cant use this rule:
RewriteEngine On
RewriteCond %{QUERY_STRING} "^type=FAQ\%20and\%20Terms$" [NC]
RewriteRule ^shopcontent\.asp$ /privacy-policy-cookie-restriction-mode/? [NC,R=301,L]

Redirecting Certain Requests into Subdir with htaccess

I'm launching a new site on WordPress but would like all of my old links to remain active. To make this possible I've moved my present site into a subdirectory (/oldsite) and installed the new wordpress site directly in root.
How would I go about redirectin any url that matches the old path style into the /oldsite directory so that:
http://example.com/stories/read/4231/some-story-title
is automatically redirected to
http://example.com/oldsite/stories/read/4231/some-story-title
The same would go for many other domain patterns like:
http://example.com/exclusives becoming http://example.com/oldsite/exclusives and a few more.
I don't want all requests to go into the /oldsite directory, since I will rely onmy WordPress instance in root.
.htaccess is still somewhat cryptic to me, so I would appreciate any direction.
Something like the following should work.
RewriteCond %{REQUEST_URI} ^/(stories|exclusives)/ [NC]
RewriteRule .* /oldsite/%1 [R=301,L]
Try this one
RewriteCond %{HTTP_HOST} ^(example.com)$ [NC]
RewriteRule ^(.*)$ /oldsite/%2%{REQUEST_URI} [QSA,L]
It will not actually redirect .. It will internally run from oldsite folder
If u want to redirect then add [R=301,L] to RewriteRule

.htaccess mod_rewrite doesnt work as I (think) i configured it

I try using mod_rewrite but it doesn't seem to work, probally a stupid error on my side.
when i go to index.php?page=home i want to make the url cleaner, I get no error but it also doesn't work
this is in my .htaccess:
RewriteEngine On # Turn on the rewriting engine
RewriteRule ^page/([A-Za-z0-9-]+)/?$ index.php?page=$1 [NC]
The rule you have in htaccess only changes new links to the old ones ie /page/something to /index.php?page=something . This doesnt handle your old links.If you don't want your old links to be accessible you can redirect them to the new url format (cleaner version) using RewriteRule.
Add the following lines above your existing rules but bellow RewriteEngine on
RewriteCond %{THE_REQUEST} /index.php\?page=([^\s]+) [NC]
RewriteRule ^ /page/%1? [L,R]
To fix the css issue see this post
Seo Friendly Url css img js not working

Categories