HTACCESS Redirect For Ecommerce Site - .htaccess

Could you please help to do a one off redirect in htaccess file from:
/something-something-something-something-c-2_19_70.html
to this type of file that does not have the number -2_:
/something-something-something-something-c-19_70.html
I am sure there is a short code that will get applied to all url of that type
Thank you very much in advance
David

Put this code in your .htaccess under DOCUMENT_ROOT:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
# redirect /something-something-something-something-c-2_19_70.html
# to /something-something-something-something-c-19_70.html
RewriteRule ^(.*)2_(.*)$ $1$2 [L,NC,R]
# redirect /ethical-jewellery-silver-c-2_19.html to /silver-c-19.html
RewriteRule ^[^-]+-[^-]+-([^-]+-)([^-]+-)2_(.*)$ $1$2$3 [L,NC,R]

Related

Rewriteurl Category Id

I want to remove my subcategory id's and redirect to new url with rewriteurl. I have lots of url like that
www.abc.com/category/(subcategoryid)-subcategory/(articleid)-article.html
Example;
www.abc.com/category/12-subcategoryA/1054-article.html
www.abc.com/category/23-subcategoryB/1072-another-article.html
vs.
to
www.abc.com/category/subcategoryA/1054-article.html
www.abc.com/category/subcategoryB/1072-another-article.html
Can you help me please.
Regards
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your DOCUMENT_ROOT/.htaccess file:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteRule ^(category)/[0-9]+-([^/]+/[^.]+\.html)$ /$1/$2 [L,NC,R=302]

How to rewrite the base URL?

I need to make a rewrite rule that if anyone writes website url (the main one),
www.domain.com
it will show
www.domain.com/1
But if someone looks for anything else, for example:
www.domain.com/2
it will show the requested url,
www.domain.com/2
I need only to rewrite the base root /.
Thank you for your help,
Adam :)
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^/?$ /1 [L]

Change URL but stay on the same page using htaccess

I have a URL:
www.example.com/property-listings/united-states/colorado/denver/denver-co-office-space
I want to stay on the same page above but simply display the URL in the address bar like this:
www.example.com/property-listings/united-states/colorado/denver/office-space
How do I accomplish this using htaccess and rewrite rules?
If I understood right, try writing a rule like this one:
RewriteEngine on
RewriteRule property-listings/united-states/colorado/denver/office-space http://www.example.com/property-listings/united-states/colorado/denver/denver-co-office-space [L]
OK. You didn't supply a pattern or mentioned there was any, so I have to guess the pattern is up to /denver/ subdirectory. Try this:
RewriteEngine on
RewriteRule ^(property-listings/united-states/colorado/denver/)(office-space)/?$ $1denver-co-$2 [L]
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^(property-listings/united-states/colorado)/(denver)/(office-space)/?$ $1/$2/$2-co-$3 [L,NC]

.HTACCESS Rewriting Issue

Can any check given code of .htaccess file and let me know what's wrong with it and why it's not working?
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^itinerary/([a-zA-Z0-9_-]+)/([0-9]+)\$ itinerary-details.php?tId=$2
I want to rewrite url as below:
www.domain.com/itinerary-details.php?tId=2&tName=agra-delhi-tour
to
www.domain.com/itinerary/2/agra-delhi-tour
and
www.domain.com/itinerary-details.php?page=1&tId=2&tName=agra-delhi-tour
to
www.domain.com/itinerary/2/agra-delhi-tour/1
Please help me in doing this.
Thanks
Seems that you have the two sections in your regex reversed. This should work for both your cases:
^itinerary/([0-9]+)/([a-zA-Z0-9_-]+)/?(.*) itinerary-details.php?tId=$1&tName=$2&page=$3
I also just noticed that you were escaping the $ which would also cause problems.
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^itinerary/([^/]+)/([^/]+)/?$ /itinerary-details.php?tId=$1&tName=$2 [L,QSA,NC]
RewriteRule ^itinerary/([^/]+)/([^/]+)/([^/]+)/?$ /itinerary-details.php?page=$3&tId=$1&tName=$2 [L,QSA,NC]

Rewrite htaccess, redirect if a "+" exisit in the url like goo.gl

my question is: how to redirect url when it contains a "+" like goo.gl and bit.ly
a simple example
http://goo.gl/gogl+ it will be redirect to http://goo.gl/info/gogl
thank in advance.
All you need is this code in your .htaccess file:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^([^\+]+)\+$ info/$1 [L]

Resources