how to Rewrite Single Page url in .htaccess - .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.

Related

Pagination Redirect with .htaccess

I want to redirect the /page/2 style pagination pages to ?page=2 and to the others in this format.
So any urls like these:
https://www.example.com/dogs/page/2
https://www.example.com/horses/videos/page/3
https://www.example.com/cats/photos/page/4
will be redirected to:
https://www.example.com/dogs?page=2
https://www.example.com/horses/videos?page=3
https://www.example.com/cats/photos?page=4
Could you please try following, written based on your shown samples. Please make sure you clear your browser cache before testing these URLs.
RewriteEngine ON
RewriteCond %{REQUEST_URI} ^/(.*?)/([^/]*)/([^/]*)/?$
RewriteRule ^(.*)$ %1?%2=%3 [L]
You may use this rule:
RewriteEngine On
RewriteRule ^(.+)/page/(\d+)/?$ $1?page=$2 [L,NC,QSA]

.htaccess rewrite rule to change path to query string? [duplicate]

Ok, im pretty new at this and I would really appreciate some help, thanks!
How can i rewrite this in .htaccess correctly?
So I have a query string in my url:
/?url=contact
All i want to do is remove the query string
/contact
Help? I scoured google and I'm learning the syntax right now, but the fact remains..I dont know how to do it just yet. Thanks to all
This was my solution:
RewriteRule ^(.*)$ index.php?url=$1 [L,QSA]
Try this:
RewriteEngine On
RewriteRule ^(.*)$ /index.php?url=$1 [L]
To a user on your site, they will see and navigate to this:
http://example.com/contact
But the real page would be something like this:
http://example.com/index.php?url=contact
This bit, [L], tells the server that this is the last line of the rewrite rule and to stop.
RewriteCond %{QUERY_STRING} url=(.*)
RewriteRule index.html %1
(or whatever if it's not index.html, index.php, whatever)
You need to capture the query string, which is not looked at by RewriteRule normally, and use the %1 back reference, not $1 as you would in a capture in a RewriteRule
Before: https://example.com/index.php?user=robert
RewriteEngine On
RewriteRule ^user/([^/]+)?$ index.php?user=$1 [L,QSA]
After: https://example.com/user/robert

Rewrite http://example.com/test.asp?index=3 to http://example.com/about

I need to Rewrite the old urls generated by ISS to a new system we have build (Joomla).
The url's had to be google friendly. What we want to happen:
Rewrite http://example.com/test.asp?index=3 to http://example.com/about
I've used a few Rewrite's i knew, but they dont work:
RewriteRule ^/test.asp?index=3 / [R=301,L]
RewriteRule ^/test.asp?index(.*)3 / [R=301,L
What pice of code am i missing/doeing wrong?
Kind regards.
You must use QUERY_STRING to check query string.
You can use this code in your htaccess (in document root folder)
RewriteEngine On
RewriteCond %{QUERY_STRING} ^index=3$ [NC]
RewriteRule ^test\.asp$ /about [R=301,L]
Note: put this rule before Joomla's rules

.htaccess 2 Dyanamic Rewrite URL

I have a dynamic url at
http://www.technicae.net/cgi-bin/type/mt-search.cgi?IncludeBlogs=2&tag=2%|tag|&limit=20
where the '|tag|' and '20' part change depending on the tag. This is Movable Type blogging platform which is written in perl. The '|tag|' part is a place holder for the tag. For example, if the tag was 'there' the url would be
http://www.technicae.net/cgi-bin/type/mt-search.cgi?IncludeBlogs=2&tag=2%there&limit=20
and not
http://www.technicae.net/cgi-bin/type/mt-search.cgi?IncludeBlogs=2&tag=2%|tag|&limit=20
I was wondering how to rewrite that in htaccess because everything I try doesn't work. I want it to be
http://www.technicae.net/tag/|tag|
instead of
http://www.technicae.net/cgi-bin/type/mt-search.cgi?IncludeBlogs=2&tag=2%|tag|&limit=20
can you please help me?
note
The URLS are not functional.
This is what you're searching for :
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^tag/([^/]+)$ cgi-bin/type/mt-search.cgi?IncludeBlogs=2&tag=2%$1 [L]
RewriteRule ^tag/([^/]+)/limit/([^/]+)$ cgi-bin/type/mt-search.cgi?IncludeBlogs=2&tag=2%$1&limit=$2 [L]
This will allow thos kind of url :
www.domain.com/tag/<myTag>
www.domain.com/tag/<myTag>/limit/<myLimit>
But not :
www.domain.com/limit/<myLimit>
Assuming you are using Apache, make sure you have mod_rewrite enabled.
The .htaccess you should use (this may need tweaked) is:
RewriteEngine On
RewriteRule ^tag/([^\.]+)$ cgi-bin/type/mt-search.cgi?IncludeBlogs=2&tag=2%$1&limit=20 [NC,L]

htaccess : rewrite urls

please help to rewrite Urls from
http://www.site.com/index.php?cat=catname
and
http://www.site.com/index.php?id=productname
to be like this
http://www.site.com/catname
and
http://www.site.com/productname
i think it will require php check if the page is cat work with it as cat
or its product work with it as product
in .htaccess file:
RewriteEngine On
RewriteRule ^([0-9a-z\-\_]+)?$ /index.php?id=$1 [L,QSA,NC]
category/product check must be done in index.php...
Or you can add extra slug
RewriteRule ^(category)/([0-9a-z\-\_]+)?$ /index.php?category=$1 [L,QSA,NC]
RewriteRule ^(product)/([0-9a-z\-\_]+)?$ /index.php?product=$1 [L,QSA,NC]
but url will look like http://site.com/category/catname
http://www.site.com/catname and http://www.site.com/productname
The problem with that scheme is that you can't tell whether it's a catalog name or a product name by the URL. As a result, you'll probably want something like this:
http://www.site.com/Catalog/catname and http://www.site.com/Product/productname
Which can then be implemented in a .htaccess file with the following rules:
RewriteEngine On
RewriteRule ^Catalog/(.+)$ /index.php?cat=$1 [L]
RewriteRule ^Product/(.+)$ /index.php?id=$1 [L]

Resources