htaccess URL Rewrite not working after 301 redirect - apache

I have the following url rewrite:
RewriteRule ^info/([^/\.]+)/?$ info.php?page=info&subpage=$1 [L]
Originally the parameters were the page id's i.e. 0-10.
I have now changed this so the URLs have more meaningful slug names to reflect the content.
I have now set up the 301 redirects, for example:
Redirect 301 /info/0 http://www.example.com/info/intro
But the problem is, the redirect doesn't go to the url rewrite (http://www.example.com/info/intro). Instead it shows the full url (http://www.example.com/info.php?page=info&subpage=0)
How can it get it to keep the rewrite?
Many thanks

As posted by LazyOne, the solution was to use RewriteRule:
RewriteRule ^info/0$ http://www.example.com/info/intro [R=301,L]

Related

Redirecting some sub pages to another format page using htaccess

I would like to add 301 redirects to specific type subpage on my site which is hosted on LAMP server.
for example,
example.com/witcher-3-100309/player-count - example.com/witcher-3-100309?tab=player-count
example.com/dota-2-100209/player-count - example.com/dota-2-100209?tab=player-count
example.com/pubg-300100/player-count - example.com/pubg-300100?tab=player-count
Is there any way in htaccess to write a general rule for all these type URLs to redirect correctly instead of individual 301 redirect codes in htaccess.
Thanks in advance.
The following should do it
RewriteEngine on
RewriteCond %{THE_REQUEST} /.+\?=([^\s]+) [NC]
RewriteRule ^.+$ %{REQUEST_URI}?tab=%1 [NE,L,R]
This will redirect /foobar/?q=value to /foobar/?tab=value .
When you sure the rule is working ok you can change the R (Temp Redirect flag) to R=301 to make the redirection permanent.

htaccess - how to redirect url with params to base url

I am trying to redirect a page.html with params at the end to the base url without params. I know I am supposed to use mod rewrite but I can't get the rules figured out. Your help will be appreciated.
Here is the scenario:
I tried this in htaccess and this rule didn't work:
redirect 301 "/page.html?p=2" http://www.domain.com/page.html
I understand from reading other posts on stackoverflow that I should write something like
^page\.html$ http://www.domain.com/page.html [QSA,NC,R=301,L]
The rules at the end [QSA,NC,R=301,L] however are incorrect. I can't figure it out. I simply want to do a 301 for this url with the p=2 parameter, and no other param.
And then process the remaining rules after this rule for other pages.
You can put this code in your root htaccess
RewriteEngine On
RewriteCond %{QUERY_STRING} ^p=2$ [NC]
RewriteRule ^page\.html$ /page.html? [R=301,L]

How to redirect URL Friendly created with rewrite

I created URL with rewrite mod.
This is the command:
RewriteRule ^productos/(.+)-(.+).html ecommerce/buscador.php?categoria=$2
Example the URL
http://www.frutasadomicilio.cl/productos/Verduras-2.html
The URL works good but now i need change the URL. I am thinking that with redirect 301 is my way an a solution. But when i try the redirect the URL, the command return the new url but with parameter.
The command is:
redirect 301 /productos/Verduras-2.html /productos/Verduras_a_domicilio-2.html
when I access the URL from google search, the Browser return this URL with parameter
http://www.frutasadomicilio.cl/productos/Verduras_a_domicilio-2.html?categoria=2
Any suggestion?
Thanks
Do not mix Redirect and RewriteRule for similar URLs. I suggest you to use only RewriteRule as
RewriteEngine on
RewriteRule ^productos/Verduras-2\.html$ /productos/Verduras_a_domicilio-2.html [R=301,L]
RewriteRule ^productos/(.+)-(.+)\.html$ ecommerce/buscador.php?categoria=$2 [NC,L]
Also, the order of the rules above is important.

redirect all URLs to domain root with htaccess rewrite

I am trying to get all requests including get variables to redirect to another domain with an htaccess rewrite,
I am trying to redirect all URLs from from my old blog to http://www.passiveincomeidea.com domain root but any URLs with a variable are still passing the variable to the new domain, like this one for example http://mika.lepisto.com/?p=2223
Here is what I have currently:
RewriteEngine On
RewriteBase /
RewriteRule ^(.*)$ http://www.passiveincomeidea.com/ [L,R=301]
How can I get the rewrite to strip all the variables during the redirect?
Thank you!
Append a question mark at the end of redirected URL:
RewriteRule ^(.*)$ http://www.passiveincomeidea.com/? [L,R=301]
For documentation, search for "Modifying the Query String" in the mod_rewrite documentation.

Simple 301 redirect in .htaccess with query string does not work with Redirect directive

I am trying to redirect a single URL in a .htaccess file with Redirect:
Redirect 301 /index2.php?option=com_rss&feed=RSS2.0&no_html=1 /something/somethingelse/
I have a bunch of other similar rules which work using directory structure URLs, but this one refuses to get processed.
Redirect 301 /old/url/ /new/url/
Do I have to do anything special?
Thanks!
With Redirect you can only test for URL paths, or more specifically, URL path prefixes but not for the URL query. But you can do so with mod_rewrite:
RewriteEngine on
RewriteCond %{QUERY_STRING} =option=com_rss&feed=RSS2.0&no_html=1
RewriteRule ^index2\.php$ /something/somethingelse/? [L,R=301]