Register Advertise with usHelp Desk Today's Posts Search

Closed Thread
Thread Tools Search this Thread
Unread 21st Jul 2014, 12:35 AM   #1
HyperActive Warrior
 
Join Date: 2011
Location: India
Posts: 165
Thanks: 65
Thanked 4 Times in 4 Posts
Default
dynamic url redirection via htaccess
Share on: 
fb share twitter share gplus share more share

Hello Warriors,

I really need help please.

I need to redirect this URL using htacess:

From this: http ://example.com/city/Chennai/search/search_display_event_type/category1

To this: http ://example.com/chennai/category1

Is there any way we can write in htacees that will redirect like below url http ://example.com/(chennai | pune | mumbai)/category1

I know this is pretty hard, but I'm really not sure what type of rule would work for this. because I dont want to write same lines of code for just city change, so i want something like array match in htaccess.

Any help is greatly appreciated!

Real Youtube & Instagram Promotion Click Here
jhakasseo is offline  
Unread 21st Jul 2014, 03:05 AM   #2
Scrum project management
 
quickscrum's Avatar
 
Join Date: 2014
Location: France
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default
Re: dynamic url redirection via htaccess
Share on: 
fb share twitter share gplus share more share

Hello jhakasseo,

Please follow this url to make your changes How do I redirect my site using a .htaccess file?

quickscrum is offline  
Unread 21st Jul 2014, 03:11 AM   #3
Active Warrior
 
Join Date: 2014
Posts: 38
Thanks: 0
Thanked 6 Times in 6 Posts
Default
Re: dynamic url redirection via htaccess
Share on: 
fb share twitter share gplus share more share

Using something like this in your .htaccess.
Code:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^city/(.*)/search/search_display_event_type/(.*)$ http://example.com/$1/$2 [R=301,L]
Kasparas is offline  
The Following User Says Thank You to Kasparas For This Useful Post:
Unread 21st Jul 2014, 05:25 AM   #4
HyperActive Warrior
 
Join Date: 2011
Location: India
Posts: 165
Thanks: 65
Thanked 4 Times in 4 Posts
Default
Re: dynamic url redirection via htaccess
Share on: 
fb share twitter share gplus share more share

Originally Posted by Kasparas View Post

Using something like this in your .htaccess.
Code:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^city/(.*)/search/search_display_event_type/(.*)$ http://example.com/$1/$2 [R=301,L]
This is what I currently have in htaccess file
dynamic redirection - Pastebin.com

on website there are more than 3000 urls that need to change from old to new.
so I am looking any dynamic solution for same.
Every city has 19 category pages.
so city + category 1, city + category 2 and the list goes on...
I want to redirect old urls to new one.
Or what will be the best way to do this?

Real Youtube & Instagram Promotion Click Here
jhakasseo is offline  
Unread 22nd Jul 2014, 03:39 PM   #5
Active Warrior
 
minirich's Avatar
 
Join Date: 2014
Location: Austria, Vienna
Posts: 52
Thanks: 16
Thanked 10 Times in 10 Posts
Default
Re: dynamic url redirection via htaccess
Share on: 
fb share twitter share gplus share more share

Originally Posted by Kasparas View Post

Using something like this in your .htaccess.
Code:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^city/(.*)/search/search_display_event_type/(.*)$ http://example.com/$1/$2 [R=301,L]
If you are using the code from Kasparas
You can remove the piece of code in line 3 and 4 and replace it with the RewriteRule above. It is dynamic.
If you want to use 301 permanent redirect, this is not for idividual urls on a website.
you only write one 301 for the entire website which will then redirect to a new domain.

Code:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^city/(.*)/search/search_display_event_type/(.*)$ http://example.com/$1/$2 [R=301,L]
The extra part with
Code:
http://example.com
is unnecessary as long as you stay on the same domain.

Hope that helps
Mike
minirich is offline  
The Following User Says Thank You to minirich For This Useful Post:
Unread 23rd Jul 2014, 01:27 AM   #6
HyperActive Warrior
 
Join Date: 2011
Location: India
Posts: 165
Thanks: 65
Thanked 4 Times in 4 Posts
Default
Re: dynamic url redirection via htaccess
Share on: 
fb share twitter share gplus share more share

@minirich

RewriteEngine on

RewriteRule ^city/(.*)$/search/search_display_event_type/(.*)$ http://www.example.org/$1/$2 [R=301,L]

this is not working and it is going to 404 page?

Real Youtube & Instagram Promotion Click Here
jhakasseo is offline  
Unread 23rd Jul 2014, 02:44 AM   #7
Active Warrior
 
minirich's Avatar
 
Join Date: 2014
Location: Austria, Vienna
Posts: 52
Thanks: 16
Thanked 10 Times in 10 Posts
Default
Re: dynamic url redirection via htaccess
Share on: 
fb share twitter share gplus share more share

Have you tried to remove the http part and starting with a /
Like that:
Code:
RewriteRule ^city/(.*)$/search/search_display_event_type/(.*)$ /$1/$2 [R=301,L]
minirich is offline  
The Following User Says Thank You to minirich For This Useful Post:
Unread 23rd Jul 2014, 05:31 AM   #8
HyperActive Warrior
 
Join Date: 2011
Location: India
Posts: 165
Thanks: 65
Thanked 4 Times in 4 Posts
Default
Re: dynamic url redirection via htaccess
Share on: 
fb share twitter share gplus share more share

Originally Posted by minirich View Post

Have you tried to remove the http part and starting with a /
Like that:
Code:
RewriteRule ^city/(.*)$/search/search_display_event_type/(.*)$ /$1/$2 [R=301,L]
Actually its working with above mention code but the problem is there is multiple cities on same structure of domain but the categories are same. However new urls I am trying to do is:

Code:
RewriteRule ^city/(.*)$/search/search_display_event_type/meeting(.*)$ /$1/$2 [R=301,L]

To RewriteRule ^city/city1|city|2|city3(.*)$/search/search_display_event_type/meeting-rooms(.*)$ /$1/$2 [R=301,L]
There are multiple categories also like meeting rooms which was mentioned as only "meetings" in old domain. Here is the main website if you like to see which are we working to change url structure example and this is how its going to look exampl.org

We are directing for search engines because there are so many webpages got indexed and want them to redirect to example.org this kind of urls.

Real Youtube & Instagram Promotion Click Here
jhakasseo is offline  
Unread 23rd Jul 2014, 03:50 PM   #9
Active Warrior
 
minirich's Avatar
 
Join Date: 2014
Location: Austria, Vienna
Posts: 52
Thanks: 16
Thanked 10 Times in 10 Posts
Default
Re: dynamic url redirection via htaccess
Share on: 
fb share twitter share gplus share more share

Ok i had a look on the page and all the possible url combinations.
This is a bit more complicated than you told in the beginning.

the structure of your urls look like that:
Code:
http://example.com/city/(city)/search/search_display_event_type/(Category)/(Location)/(Capacity)/(Configuration)
while city can by any of 8 specified
Category is one of these: Wedding+Reception, Meetings, Conference, Brithday-Party, Private-Party
Location: depends on the city and can be a whole lot to choose from
Capacity: a range in the form of low-high
Configuration: the arrangement of the seating can be one of 7 (Conference-Style, U-Shape, Holow-Square-style, Theater-style, Classroom-style, open, cluster)

while city and category are mandatory to see any result, Location, Capacity and Configuration are optional but will appear in a specific order.
The following rules will be the result: the order is important.
Code:
RewriteBase /
# just the city
RewriteRule ^(.*)$ /city/$1 [NC, L] 
# city with category
RewriteRule ^(.*)/(.*)$ /city/$1/search/search_display_event/$2 [NC, L]
# city with category and Configuration
RewriteRule ^(.*)/(.*)/(Conference-Style|U-shape|Holow-square-style|Theater-style|Classroom-style|Open|Cluster)$ /city/$1/search/search_display_event/$2/$3 [NC,L]
# city with category and Capacity
RewriteRule ^(.*)/(.*)/([d]+-[d]+)$ /city/$1/search/search_display_event/$2/$3 [NC,L]
# city with category and location
RewriteRule ^(.*)/(.*)/([D-]*)$ /city/$1/search/search_display_event/$2/$3 [NC,L]
# city with category Location  and Configuration
RewriteRule ^(.*)/(.*)/([D-]*)/(Conference-Style|U-shape|Holow-square-style|Theater-style|Classroom-style|Open|Cluster)$ /city/$1/search/search_display_event/$2/$3/$4 [NC,L]
# city with category capacity and configuration
RewriteRule ^(.*)/(.*)/([d]+-[d]+)/(Conference-Style|U-shape|Holow-square-style|Theater-style|Classroom-style|Open|Cluster)$ /city/$1/search/search_display_event/$2/$3/$4 [NC,L]
# city with category location and capacity
RewriteRule ^(.*)/(.*)/([D-]*)/([d]+-[d]+)$ /city/$1/search/search_display_event/$2/$3/$4 [NC,L]
# city with category location capacity and configuration
RewriteRule ^(.*)/(.*)/([D-]*)/([d]+-[d]+)/(Conference-Style|U-shape|Holow-square-style|Theater-style|Classroom-style|Open|Cluster)$ /city/$1/search/search_display_event/$2/$3/$4/$5 [NC,L]
These rules should be able to handle all the following url permuations:
Code:
http://example.com/Mumbai
http://example.com/Mumbai/Meetings
http://example.com/Mumbai/Meetings/Cluster
http://example.com/Mumbai/Meetings/1-500
http://example.com/Mumbai/Meetings/Dadar
http://example.com/Mumbai/Meetings/Dadar/Cluster
http://example.com/Mumbai/Meetings/Dadar/1-500
http://example.com/Mumbai/Meetings/1-500/Cluster
http://example.com/Mumbai/Meetings/Dadar/1-500/Cluster
I hope i did not add any nasty typos. (It is already late).
And if some one out there knows a way to optimize this feel free to comment.

Hope that helps
Mike
minirich is offline  
The Following User Says Thank You to minirich For This Useful Post:
Unread 23rd Jul 2014, 11:50 PM   #10
HyperActive Warrior
 
Join Date: 2011
Location: India
Posts: 165
Thanks: 65
Thanked 4 Times in 4 Posts
Default
Re: dynamic url redirection via htaccess
Share on: 
fb share twitter share gplus share more share

Originally Posted by minirich View Post

Ok i had a look on the page and all the possible url combinations.
This is a bit more complicated than you told in the beginning.

the structure of your urls look like that:
Code:
http://example.com/city/(city)/search/search_display_event_type/(Category)/(Location)/(Capacity)/(Configuration)
while city can by any of 8 specified
Category is one of these: Wedding+Reception, Meetings, Conference, Brithday-Party, Private-Party
Location: depends on the city and can be a whole lot to choose from
Capacity: a range in the form of low-high
Configuration: the arrangement of the seating can be one of 7 (Conference-Style, U-Shape, Holow-Square-style, Theater-style, Classroom-style, open, cluster)

while city and category are mandatory to see any result, Location, Capacity and Configuration are optional but will appear in a specific order.
The following rules will be the result: the order is important.
Code:
RewriteBase /
# just the city
RewriteRule ^(.*)$ /city/$1 [NC, L] 
# city with category
RewriteRule ^(.*)/(.*)$ /city/$1/search/search_display_event/$2 [NC, L]
# city with category and Configuration
RewriteRule ^(.*)/(.*)/(Conference-Style|U-shape|Holow-square-style|Theater-style|Classroom-style|Open|Cluster)$ /city/$1/search/search_display_event/$2/$3 [NC,L]
# city with category and Capacity
RewriteRule ^(.*)/(.*)/([d]+-[d]+)$ /city/$1/search/search_display_event/$2/$3 [NC,L]
# city with category and location
RewriteRule ^(.*)/(.*)/([D-]*)$ /city/$1/search/search_display_event/$2/$3 [NC,L]
# city with category Location  and Configuration
RewriteRule ^(.*)/(.*)/([D-]*)/(Conference-Style|U-shape|Holow-square-style|Theater-style|Classroom-style|Open|Cluster)$ /city/$1/search/search_display_event/$2/$3/$4 [NC,L]
# city with category capacity and configuration
RewriteRule ^(.*)/(.*)/([d]+-[d]+)/(Conference-Style|U-shape|Holow-square-style|Theater-style|Classroom-style|Open|Cluster)$ /city/$1/search/search_display_event/$2/$3/$4 [NC,L]
# city with category location and capacity
RewriteRule ^(.*)/(.*)/([D-]*)/([d]+-[d]+)$ /city/$1/search/search_display_event/$2/$3/$4 [NC,L]
# city with category location capacity and configuration
RewriteRule ^(.*)/(.*)/([D-]*)/([d]+-[d]+)/(Conference-Style|U-shape|Holow-square-style|Theater-style|Classroom-style|Open|Cluster)$ /city/$1/search/search_display_event/$2/$3/$4/$5 [NC,L]
These rules should be able to handle all the following url permuations:
Code:
http://example.com/Mumbai
http://example.com/Mumbai/Meetings
http://example.com/Mumbai/Meetings/Cluster
http://example.com/Mumbai/Meetings/1-500
http://example.com/Mumbai/Meetings/Dadar
http://example.com/Mumbai/Meetings/Dadar/Cluster
http://example.com/Mumbai/Meetings/Dadar/1-500
http://example.com/Mumbai/Meetings/1-500/Cluster
http://example.com/Mumbai/Meetings/Dadar/1-500/Cluster
I hope i did not add any nasty typos. (It is already late).
And if some one out there knows a way to optimize this feel free to comment.

Hope that helps
Mike
Hello Mike,

Thank you very much for taking time to see website and replying. I really appreciate.

The one thing that I also forget to add that the category like meetings etc going to change from meetings to meeting-halls, from wedding+reception to wedding-reception-halls etc.

So this is also I want to add in htaccess with above mention solution. Need help on this actually.

The actual urls look likes as below with all lowercase letters.
Code:
http://www.example.com/mumbai
http://www.example.com/mumbai/meeting-halls
http://www.example.com/mumbai/meeting-halls/cluster
http://www.example.com/mumbai/meeting-halls/1-500
http://www.example.com/mumbai/meeting-halls/dadar
http://www.example.com/mumbai/meeting-halls/dadar/cluster
http://www.example.com/mumbai/meeting-halls/dadar/1-500
http://www.example.com/mumbai/meeting-halls/1-500/cluster
http://www.example.com/mumbai/meeting-halls/dadar/1-500/cluster
I know I already ate lots of your precious time but you have been a very helpful for me till the time. I really appreciate that.

Real Youtube & Instagram Promotion Click Here
jhakasseo is offline  
Unread 24th Jul 2014, 06:43 AM   #11
Active Warrior
 
minirich's Avatar
 
Join Date: 2014
Location: Austria, Vienna
Posts: 52
Thanks: 16
Thanked 10 Times in 10 Posts
Default
Re: dynamic url redirection via htaccess
Share on: 
fb share twitter share gplus share more share

It should work for any kind of category. The rules contain a regular expression (.*) this will match every character.
The only thing which needs to be changed is if you change to configuration values.
(Conference-Style|U-shape|Holow-square-style|Theater-style|Classroom-style|Open|Cluster)
if you have your new configuration names. just search the old name and replace it with the new name.

Just send me a pm or skype me when you need help there too.
Mike
minirich is offline  
The Following User Says Thank You to minirich For This Useful Post:
Unread 24th Jul 2014, 11:46 PM   #12
HyperActive Warrior
 
Join Date: 2011
Location: India
Posts: 165
Thanks: 65
Thanked 4 Times in 4 Posts
Default
Re: dynamic url redirection via htaccess
Share on: 
fb share twitter share gplus share more share

Originally Posted by minirich View Post

It should work for any kind of category. The rules contain a regular expression (.*) this will match every character.
The only thing which needs to be changed is if you change to configuration values.
(Conference-Style|U-shape|Holow-square-style|Theater-style|Classroom-style|Open|Cluster)
if you have your new configuration names. just search the old name and replace it with the new name.

Just send me a pm or skype me when you need help there too.
Mike
It should work for any kind of category. The rules contain a regular expression (.*) this will match every character.
This is the main problem we are also not matching every character hence there are changes in some characters while redirecting. means the category pattern dont match with new category. They are new keywords in url. but the content they will show from old url. meetings to meeting hall.
How to identify and put non match query to get it redirect.

Real Youtube & Instagram Promotion Click Here
jhakasseo is offline  
Unread 25th Jul 2014, 01:05 AM   #13
Active Warrior
 
minirich's Avatar
 
Join Date: 2014
Location: Austria, Vienna
Posts: 52
Thanks: 16
Thanked 10 Times in 10 Posts
Default
Re: dynamic url redirection via htaccess
Share on: 
fb share twitter share gplus share more share

If it is not possible to use the values directly in the redirect we have to use a rewrite mapping.

The problem i have is, i'm the next 8 to 10 days offline.
If you need it really urgent i will try to do it today.
But i need a list of the values and to what they should be mapped to.

Mike
minirich is offline  
The Following User Says Thank You to minirich For This Useful Post:
Unread 28th Jul 2014, 04:15 AM   #14
HyperActive Warrior
 
Join Date: 2011
Location: India
Posts: 165
Thanks: 65
Thanked 4 Times in 4 Posts
Default
Re: dynamic url redirection via htaccess
Share on: 
fb share twitter share gplus share more share

Originally Posted by minirich View Post

If it is not possible to use the values directly in the redirect we have to use a rewrite mapping.

The problem i have is, i'm the next 8 to 10 days offline.
If you need it really urgent i will try to do it today.
But i need a list of the values and to what they should be mapped to.

Mike
Hello Mike thank you... Above solution really help me and it worked..

Now I want to redirect
from http:// xyz.com/city/Pune/welcome/venue_display/Abc-Xyz/Locality to http:// www. xyz.com/pune/abc-xyz/locality

I want some part of url in lowercase example: (Abc-Xyz/Locality to abc-xyz/locality)

So is there any rewrite rule or anything that I want to mention in htaccess for this specific?

Real Youtube & Instagram Promotion Click Here
jhakasseo is offline  
Unread 12th Aug 2014, 02:25 AM   #15
Active Warrior
 
minirich's Avatar
 
Join Date: 2014
Location: Austria, Vienna
Posts: 52
Thanks: 16
Thanked 10 Times in 10 Posts
Default
Re: dynamic url redirection via htaccess
Share on: 
fb share twitter share gplus share more share

Hi,
sorry for answering now, i extended the vacation, because my wife and kids wanted to burry their feet in the beach sand for another week.

There is a way to sort the uppercase problem in the redirect rules, but i have to research it a bit, because currently i belive it is only working in the virtual host configuration.

Have you got the list for the category substitutions (meeting -> meeting-halls) ready, i will try to fix this in one big swoop.

Mike

Last edited on 12th Aug 2014 at 02:25 AM. Reason: typo
minirich is offline  
The Following User Says Thank You to minirich For This Useful Post:
Unread 12th Aug 2014, 03:08 AM   #16
HyperActive Warrior
 
Join Date: 2011
Location: India
Posts: 165
Thanks: 65
Thanked 4 Times in 4 Posts
Default
Re: dynamic url redirection via htaccess
Share on: 
fb share twitter share gplus share more share

Originally Posted by minirich View Post

Hi,
sorry for answering now, i extended the vacation, because my wife and kids wanted to burry their feet in the beach sand for another week.

There is a way to sort the uppercase problem in the redirect rules, but i have to research it a bit, because currently i belive it is only working in the virtual host configuration.

Have you got the list for the category substitutions (meeting -> meeting-halls) ready, i will try to fix this in one big swoop.

Mike
Hello Mike,

Yeah good to see you back..

Finally I found the way to solve all issues with combination of htaccess and config file from hosting. Redirected all old urls to new with lowercase.

So many thanks to you bro..

Real Youtube & Instagram Promotion Click Here
jhakasseo is offline  
Unread 12th Aug 2014, 11:52 AM   #17
Active Warrior
 
minirich's Avatar
 
Join Date: 2014
Location: Austria, Vienna
Posts: 52
Thanks: 16
Thanked 10 Times in 10 Posts
Default
Re: dynamic url redirection via htaccess
Share on: 
fb share twitter share gplus share more share

Great, so your happy?

Mike
minirich is offline  
Closed Thread


Bookmarks

Tags
dynamic, htaccess, redirection, url


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT -6. The time now is 05:56 PM.