Url Rewriting for Html pages - apache

I am using .htaccess for url redirect. I have tried lot of things but it is giving me "NOT FOUND" ERROR
My current Url is
http://localhost:8089/travell/search.html?/india/goa
I need the url to be
http://localhost:8089/vacation/india/goa
My htaccess file is having
RewriteRule ^(.*)?search.html http://localhost:8089/vacation?%{Query_string} [P]

You're doing reverse in your rule. Use this rule in root .htaccess:
RewriteEngine On
RewriteRule ^vacation/(.+)$ travell/search.html?$1 [L,NC,QSA]
Then test it by entering http://localhost:8089/vacation/india/goa in browser.

Related

Redirect with .htaccess but getting old URL as parameter

I want to create a .htaccess file which redirects me from
https://example.net/#UserName to https://example.net/user/index.php?user=UserName, but only when there is the #.
Can someone please help me?
You can use this in your htaccess file:
RewriteEngine On
RewriteRule ^#([^/]+)/?$ https://example.net/user/index.php?user=$1 [L,R]
This will redirect a URL of the form example.com/#foobar to https://example.net/user/index.php?user=foobar changing the URL in browser address bar. However, if you do not want the URL to change, use the following instead
RewriteEngine On
RewriteRule ^#([^/]+)/?$ /user/index.php?user=$1 [L]

RedirectMatch adding extra url segments

I'm trying to redirect requests for our old blog to a new url on a subdomain.
The old url looks like
https://www.website.com/blog-name/post/slug-of-the-title
and it needs to redirect to
https://stage.website.com/blog-name/slug-of-the-title
I'm using this rule in my .htaccess
RedirectMatch ^/blog-name/post/(.*)$ https://stage.website.com/blog-name/$1
And I'm getting redirected to the correct page, but my urls have extra segments on the end. Like
https://stage.website.com/blog-name/slug-of-the-title/?/blog-name/post/slug-of-the-title
What am I doing wrong?
With your shown samples, could you please try following. Please clear your browser cache before testing your URLs. Make sure you keep these rules at the top of your .htaccess rules file(in case you have any more rules also in your .htaccess file).
RewriteEngine ON
RewriteCond %{HTTP_HOST} ^(?:www\.)?website\.com$ [NC]
RewriteRule ^blog-name/post/(.*)/?$ https://stage.website.com/blog-name/$1? [NC,R=301,L]

.htaccess mod_rewrite redirect without query string variables not working

I'm having a problem with one of my rewrite rules. I would like to redirect all of the following URL's to another URL without the query string.
/gallery/products.aspx?C=9&SC=&ID=428&P=10
/gallery/products.aspx?C=2&SC=2&ID=128&P=1
/gallery/products.aspx?ID=147&C=2&SC=&P=7
/gallery/products.aspx?ID=1337&C=15&SC=&P=1
/gallery/products.aspx?ID=1532&C=3&SC=&P=2
/gallery/products.aspx?C=9&SC=&ID=1489&P=1
/gallery/products.aspx?C=7&SC=&ID=100&P=2
/gallery/products.aspx?C=2
/gallery/products.aspx?ID=1328&C=14&SC=11&P=17
/gallery/products.aspx?C=1&SC=&ID=767&P=3
/gallery/products.aspx?ID=1270&C=1&SC=&P=26
and I have this in my .htaccess file
RewriteRule ^gallery/products.aspx http://www.domain.com/category/? [L,R=301]
but it's not working. I checked it in a .htaccess simulator and it found the rule then redirected, but when I upload to my server, it doesn't redirect. I've also tried some other rules with no luck
I was finally able to make this work with the following:
RewriteCond %{HTTP_HOST} www.domain.com [NC]
RewriteRule products.aspx http://www.domain.com/category? [L,R=301]

url rewrites dynamic urls redirects - Magento

I'm looking for htaccess lines that do the following
Redirect old existing urls to new url (301)
Example
www.example.com/categorya/categoryb/product.htm
TO
www.example.com/product.htm
There can be more category parts, or less, it all has to go to /product.htm (Magento).
Who can help?
Try putting these rules in the htaccess file in your document root, preferably above any rules that you may already have there:
RewriteEngine On
RewriteRule ^(.+)/product.htm$ /product.htm [L,R=301]
Try:
RewriteEngine On
RewriteRule ^[^/]+/[^/]+/([^.]+)\.htm$ /$1.htm [L,R=301]

Rewrite URLs Using .htaccess

Referring to the article here I created my .htaccess file with the following lines
RewriteEngine on
RewriteRule ^/product/([0-9]+)/(.*)$ /index.php?route=product&product=$1 [L]
but this doesn't work and I get a 404 error.
I want URLs like
http://localhost/product/12/some-random-text.html
to be redirected to
http://localhost/index.php?route=product&product=12
I am using GoDaddy's Linux hosting
Try changing your RewriteRule to:
RewriteRule ^product/([0-9]+)/(.*)$ /index.php?route=product&product=$1 [QSA,L]