How to remove specific character from url using htaccess - .htaccess

We want to remove specific characters from the url using htaccess.
for example http://www.example.com/#/music.php which is redirect to http://www.example.com/music.php using htaccess rules.
we used the following code but its not working
RewriteEngine On
RewriteRule ^\.html$ /#/music.php [L]

Related

Rewrite URL through .htaccess

My website generates page URL with the prefix ?Script=, which is not SEO-friendly.
I want to remove this prefix and just keep the page title.
For example, I want to convert the following URL:
example.com/?Script=about to example.com/about
about is the About page of my website.
I want to set up a rule for omitting ?Script= for all pages.
I have managed to do it for my blog post by using the following rewrite rule.
RewriteRule ^news/([0-9a-zA-Z_-]+) ?Script=news_view&uid=$1
This should work for you .
RewriteEngine on
RewriteRule ^(about)/?$ /?script?=$1 [L]
If you have more pages , you can add those pages to the pattern
RewriteEngine on
RewriteRule ^(about|page2|page3)/?$ /?script?=$1 [L]

Redirect URL using rewrite rules- https://hostname/en/<content-page> to https://hostname/en/<storename>/content-page>

Redirect dynamic URL for below example :
https://hostname/en/content-page
to
https://hostname/en/storename/content-page
content-page is the dynamic parameters Like-
https://hostname/en/grocery/vegetables?fetchFacets=true#facet:&productBeginIndex:0&facetLimit:&orderBy:&pageView:grid&minPrice:&maxPrice:&pageSize:&
to
https://hostname/en/storename/grocery/vegetables?fetchFacets=true#facet:&productBeginIndex:0&facetLimit:&orderBy:&pageView:grid&minPrice:&maxPrice:&pageSize:&
OR
http://hostname/en/electronics?fetchFacets=true#facet:&productBeginIndex:0&facetLimit:&orderBy:&pageView:grid&minPrice:&maxPrice:&pageSize:&
to
http://hostname/en/storename/electronics?fetchFacets=true#facet:&productBeginIndex:0&facetLimit:&orderBy:&pageView:grid&minPrice:&maxPrice:&pageSize:&
add /storename or /en/storename in dynamic URLs
You should be able to just put /en/ in your pattern and then substitute it with an appended storename. Add this to your .htaccess file:
RewriteEngine On
RewriteRule ^en/(.*)$ https://hostname.com/en/storename/$1 [R=301,L]
That will redirect as you've asked in your examples.

Redirect all urls which contain certain parameters to another url which follows a certain pattern

Unfortunately I didn't get it solved by myself and need to ask for help. I want to redirect all urls which follow a certain pattern (in this case it contains "reviews/category"). These URLs supposed to be redirect to another url which is made up the first one:
http://[product-url]/reviews/category/[category-url]
supposed to be redirect to
http://[product-url].html
Furthermore it shouldn't matter if you call the url with or without www.
Example:
http://example.com/ford-blues/reviews/category/cars supposed to be redirect to http://example.com/ford-blues.html
Any help would be much appreciated.
Following code isn't working
RewriteEngine On
RewriteRule ^reviews/category/?$ $1\.html [R=301,L]
Try:
RedirectMatch 301 ^(.*)/reviews/category/ /$1.html
in the htaccess file in your document root.
Or using mod_rewrite:
RewriteEngine On
RewriteRule ^(.*)/reviews/category/ /$1.html [L,R=301]

htacess url rewrites for .php?=n

I'm looking to rewrite old PHP pages to new locations, however the previous system used URLs structured as follows:
/old-page.php?page=Our%20Services
I've tried the following:
Redirect 301 /old-page.php?page=Our%20Services http://www.newdomain.co.uk/our-services/
Can someone help explain to me why the rewrite rule ignores everything after the question mark please?
You can use Redirect for simple cases only. If you want to check the query string, you must use mod_rewrite and RewriteCond
RewriteEngine on
RewriteCond %{QUERY_STRING} page=Our%20Services
RewriteRule ^old-page.php$ http://www.newdomain.co.uk/our-services/ [R,L]
This checks, if the query string contains page=Our%20Services and the URL path is old-page.php. It then redirects the client to the new URL http://www.newdomain.co.uk/our-services/.

.htaccess: rewrite URL with query strings

I need to rewrite a URL using an .htaccess and the URL has two query strings. Here is my raw URL:
http://domain.com/channel-partners/en/index.php?location=phoenix-az&name=company
How do I get that to be written as:
http://cp.domain.com/phoenix-az/company
RewriteEngine On
RewriteBase /
RewriteRule ^partners/([\w-]+)/([\w-]+)/?$ channel-partners/en/index.php?location=$1&name=$2 [L]
This will redirect URLs in the format partners/location/name with an optional trailing slash to the raw URL you provided. location and name can be alphanumeric, underscore, or dash characters.
Note: I have prefixed the URL with the literal partners. Without it your RewriteRule would be too loose and match nearly all requests. Feel free to change it.
UPDATE
To redirect from your sub-domain, the above needs to be in the .htaccess file for cp.domain.com. You'll need to modify your RewriteRule to the following:
RewriteRule ^partners/([\w-]+)/([\w-]+)/?$ http://domain.com/channel-partners/en/index.php?location=$1&name=$2 [L]
However, I really don't recommend this. Link management is going to be a nightmare. You should really try to have all these links under the same domain. 301 Redirect from the sub-domain if you have to.

Resources