RewriteRule with 1 aliased path - .htaccess

I want to redirect several pages to a same page :
/products/categories-35512 > /catalog/products
/products/categories-152 > /catalog/products
/products/categories-5632 > /catalog/products
...
For this, I need to use an alias. I tried to use this code in my .htaccess without success:
RewriteEngine On
RewriteRule ^/products/categories\/(.*)$ /catalog/products [L,R=301,NE]
How do I proceed to resolve my problem?
Thanks for your help.

Try this
RewriteEngine On
RewriteRule ^categories http://www.example.com/catalog/products/ [R=301,L]
This will redirect all the URLs that start with categories to
/catalog/products/

Related

.htaccess redirect to subdomain with regex

I want to 301 redirect a specific path to another subdomain with htaccess
I want :
A : http://www.example.org/markets/access/id/56
B : http://www.example.org/markets/market/id/56
to redirect to :
A : https://archive.example.org/markets/access/id/56
B : https://archive.example.org/markets/market/id/56
I have tried this but get an error 500:
RewriteCond http://www.example.org/markets/(.+?)
RewriteRule https://archive.example.org/markets/$1 [R=301,L]
Thank you
Based on your shown samples, could you please try following. Please make sure you put these rules at the top of your .htaccess file.
Also make sure you clear your browser cache before testing your URLs.
RewriteEngine ON
RewriteCond %{HTTP_HOST} ^www\.(example\.org)$ [NC]
RewriteRule ^ https://archive.%1%{REQUEST_URI} [NE,R=301,L]

How to get /folder/subfolder to display as /subfolder/ using htaccess

I'm trying to do the following...
Original path that needs to be rewritten, renamed, or redirected:
http://www.example.com/_plugin/notifications/
to:
http://www.example.com/notifications/
via root htaccess file...Any help would be greatly appreciated!
=================================================================
This does not work:
RewriteEngine On
RewriteRule ^/_plugin/notifications$ /notifications [L]
This does not work either:
RewriteEngine On
RedirectMatch ^/_plugin/notifications$ /notifications/
This does not work either:
RewriteEngine On
RewriteRule ^notifications/(.*)$ /notifications$1 [R=301,NC,L]
=============================
EDIT
With the help of #Starkeen - I have a few follow up questions to this.
Is there a way to shorten the .htaccess file up though if lets say I
have multiple subfolders within the folder instead of writing that 1
condition and the 2 rules for each subfolder?
How would I allow subfolders of the subfolder to display? Currently it is throwing a 404 at me... :(
============
Still need help with follow-up question #1, but I believe I got question #2.
SOLUTION (I believe) to follow-up question #2:
RewriteCond %{THE_REQUEST} /_plugin/notifications/ [NC]
RewriteRule ^_plugin/notifications/(.*)$ /notifications/$1 [L,R]
RewriteRule ^notifications/(.*)$ /_plugin/notifications/$1 [L]
None of the rules you have tried are correct.
To redirect /folder/subfolder to /root/subfolder you need a permanent 301 Redirect rule something like the following :
RewriteEngine on
RewriteCond %{THE_REQUEST} /folder/subfolder/ [NC]
RewriteRule ^folder/subfolder/$ /subfolder/ [L,R]
The above will redirect http://example.com/folder/subfolder/ to http://example.com/subfolder .
You will get a 404 error if the /subfolder/ doesn't exist in the root dir. To avoid the 404 error you can rewrite the /subfolder/ uri back to its original location /folder/subfolder/ using an internal Rewrite just bellow the first one
:
RewriteRule ^subfolder/?$ /folder/subfolder/ [L]

Redirect URL changing QUERY string parameter ? to & with .htaccess

I am trying to change this url:
http://blabla.nl/download/?url=https://www.bla.com/see?v=345345&type=download
to this:
http://blabla.nl/download/?url=https://www.bla.com/see&v=345345&type=download
Using .htaccess
so the ? needs to change to an &.
at the moment i am not very succesfull fixing this.
You have to do it this way:
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} ^(url=https://www\.youtube\.com/watch)\?(v=[A-Za-z0-9]+&type=downloa‌​d)
RewriteRule ^/?8/downloadff/?$ /8/downloadff/?%1&%2 [R=301,NC,L]
I assume that the number 345345 is always a number an will be different all the times but the rest keeps the same.
Put this as .htaccess file on http://example.nl/ or http://example.nl/download/
Try this:
RewriteEngine On
RewriteRule ^download/?url=https://www.bla.com/see&v=345345&type=download/?$ download/?url=https://www.bla.com/see?v=345345&type=download [NC,L]
I hope it works for you.

how to Rewrite Single Page url in .htaccess

I need to rewrite only 1 specific URL
from
http://www.domainname.com/index.php?route=payment/axis/callback
to
http://www.domainname.com/payment/axis/callback
I tried these two from stack overflow, I don't know why its not working
1st one :
RewriteRule ^([A-Za-z0-9-]+)/?$ index.php?route=payment/axis/callback [NC,L]
2nd one :
RewriteRule ^index.php?route=payment/axis/callback payment/axis/callback [L]
Try this:
4) Rewriting yoursite.com/user.php?username=xyz to yoursite.com/xyz
Have you checked zorpia.com.If you type http://zorpia.com/roshanbh233 in browser you can see my profile over there. If you want to do the same kind of redirection i.e http://yoursite.com/xyz to http://yoursite.com/user.php?username=xyz then you can add the following code to the .htaccess file.
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)$ user.php?username=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ user.php?username=$1
See the full page here.
Hope it helps!
I wouldn't use .htaccess with RewriteRule, since there are often problems with it. A simple workaround (with PHP redirect):
<?php
if($_GET['route'] == 'payment/axis/callback') {
header("Location: http://www.domainname.com/payment/axis/callback");
}
?>
You can either use h0ch5tr4355's workaround or you can try this:
RewriteEngine on
RewriteCond %{QUERY_STRING} ^route=payment/axis/callback$
RewriteCond %{SCRIPT_FILENAME} index.php
RewriteRule (.*) /payment/axis/callback [NC,QSD]
If you instead of a rewrite would like it to redirect to the new url you can add R=301 to the flags of the RewriteRule.

.htaccess php to html

sorry for this simple question, however i still cant get my head round using .htaccess
I'm trying to convert:
search.php?s=dvd&page=1
to
/Search/dvd/page1.html
Thanks,
Jack
I think something like:
RewriteRule ^search/([A-Za-z]+)/page([0-9]+)\.html$ search.php?$1&page$2
Should do the trick.
Further reading here: http://www.webforgers.net/mod-rewrite/mod-rewrite-syntax.php
you must put your link "/Search/dvd/page1.html" in the page and with htaccess it will convert to the "search.php?s=dvd&page=1" . i hope it be usefull :)
sample correct htaccess code :
RewriteEngine On
RewriteRule Search/(\d+)/page?(\d+)\.html$ search.php?s=$1&page=$2 [NC,L]
If I understand the question OP wants to convert php to html redirection. Try this rule in your .htaccess file:
RewriteEngine on
Options +FollowSymlinks -MultiViews
# to match /search.php?s=dvd&page=1
RewriteCond %{QUERY_STRING} ^s=([^&]*)&page=(.*)$ [NC]
RewriteRule ^search\.php/?$ /Search/%1/page%2.html? [R,L,NC]
# to match /search.php?page=12&s=dvd
RewriteCond %{QUERY_STRING} ^page=([^&]*)&s=(.*)$ [NC]
RewriteRule ^search\.php/?$ /Search/%2/page%1.html? [R,L,NC]
R=301 will redirect with https status 301
L will make last rule
NC is for no case comparison
%1 and %2 are the query parameter values
I think you want make clean URI, so if user type url like this:
search/televisi/page4.html
it same as like search.php?s=dvd&page=1
Add this code:
RewriteEngine On
RewriteRule ^search/([a-z]+)/page([1-9]+).html$ search.php?s=$1&page=$2

Resources