homepage Welcome to WebmasterWorld Guest from 107.22.70.215
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
Url redirection by mod rewrite
Url redirection by mod rewrite
fahad direct




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

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([^/]*)/(.*)$

 

jdMorgan




msg:4203679
 5:29 pm on Sep 18, 2010 (gmt 0)

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

fahad direct




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

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.

Spiekerooger




msg:4203811
 11:26 am on Sep 19, 2010 (gmt 0)

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

fahad direct




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

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?

jdMorgan




msg:4203871
 3:10 pm on Sep 19, 2010 (gmt 0)

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

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved