Welcome to WebmasterWorld Guest from 54.205.170.21

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Url redirection by mod rewrite

Url redirection by mod rewrite

   
2:21 pm on Sep 18, 2010 (gmt 0)

5+ Year Member



Is it really esential to do URL redirection if url mod rewrite is performed? I have already done mod rewrite but If i can have references how to do URL redirection or if can get help for:

RewriteRule ^([15]+)1([0-9]+)0([0-9]+)-PG([0-9]*)-([0-9]*)-V(.*)/P([~A-Za-z0-9]*)-S([^/]*)/(.*)$
5:29 pm on Sep 18, 2010 (gmt 0)

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Hi Fahad, and welcome to WebmasterWorld!

I'm afraid I cannot understand your question.

In order to understand this, we'll need to know if you want an external client redirect from one URL to a different URL, or an internal URL-to-filepath rewrite, or some other function.

An example of the "input" and the desired "output" would be most helpful. Please describe your "goal" or "purpose" and provide example URLs and filepaths as appropriate.

The regular expressions pattern you show above is extremely inefficient, and avoiding an early server upgrade may require a change to the design of your linked URLs.

Jim
10:25 am on Sep 19, 2010 (gmt 0)

5+ Year Member



Hi Jim,
Thanks.

My question was about redirection URLs after finishing mod rewrite as i have 2 URLs now one default URL something like example.com/index.php?var1=x&var2=y&var3=z and same page can be accessed by new rewritten URL. If google crawls, will find both pointing to the same page.



Regards.
11:26 am on Sep 19, 2010 (gmt 0)

5+ Year Member



Hi Fahad,

if I understand your concern right, you have the following:

A clean virtual URL without a query string that is pointing internally thru mod_rewrite to index.php?var1=x&var2=y.....

Now you want this page only to be accessed by the clean virtual URL, not the index.php with the query string.

First of all, it's the job of your cms to point to the URL you want to have displayed (the clean virtual URL) and it's mod_rewrites job to present the content of the original file once the clean virtual URL is accessed.

But if you do have old backlinks pointing to the real URL or those real URLs are indexed by Search Engines, you could do the following:


#Redirect external requests at real url to virtual url
RewriteCond %{THE_REQUEST} ^real_url$
RewriteRule ^(.*)$ http://www.example.com/virtual_url [R=301,L]
#Grabbing content from real_url while keeping virtual_url displayed
#in the browser
RewriteRule ^virtual_url$ /real_url [L]


If these instructions won't help, please provide us with an exact answer to jdMorgans questions so we can understand what you are up to.

Chris
2:57 pm on Sep 19, 2010 (gmt 0)

5+ Year Member



Hi Chris,
Great thanks. It really helped. If i have 10 URLs rewrite rules in my .htaccess do i need to put 10 redirections, seaparately for each?
3:10 pm on Sep 19, 2010 (gmt 0)

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member



The concept is much easier to understand if the correct terminology is used, particularly making a distinction between URLs and file paths:

# Externally redirect direct client requests for old unfriendly URLs to new friendly URLs
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /old_url_plus_query_string HTTP/
RewriteRule ^old_url$ http://www.example.com/new_url [R=301,L]
#
# Internally rewrite requests for new friendly URLs to index.php script filepath plus query string
RewriteRule ^new_url$ /script_filepath_plus_query [L]

Note also the form of THE_REQUEST, which is the entire HTTP request line as it appears in your raw server access logs, for example:
GET /index.php?var1=x&var2=y&var3=z HTTP/1.1

The old search-engine-unfriendly url-path used to be the same as the internal server filepath.

Now we are using (linking to) a new search-engine-friendly URL (it is a real URL and there is nothing 'virtual' about it), and we are mapping that URL, when requested from the server, to the correct internal filepath+query string needed to generate the content for that new URL.

So this new rule is used to redirect client requests (and only client requests) for the old URL to the new URL.

You may need ten new redirect rules, or you may need fewer. It all depends on the old URLs that you need to redirect, and whether you can devise regular-expressions patterns that will allow you use fewer than ten rules (by "sharing" one rule so that it redirects more than one of the ten "kinds" of the old URLs).

Jim
 

Featured Threads

Hot Threads This Week

Hot Threads This Month