Forum Moderators: phranque

Message Too Old, No Replies

url redirect and then a rewrite

without effecting the other rewrite rules

         

itaine

11:18 pm on Aug 16, 2007 (gmt 0)

10+ Year Member



Can anyone help me with redirecting my root url (ie: [agent.alpha...] to point to [agent.alpha...]

then

rewrite it back to the home address (ie. [agent.alpha...]

Is this possible? If so what is the most elegant way to implement it without disrupting future rules. Also, don't know if its relevant or not but, once development is fleshed out the [agent.alpha...] turns into yada yada.com.

thx in advance

g1smd

11:48 pm on Aug 16, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The most important URL on a site is the root index page / root page.

You want the shortest possible URL, like domain.com/ or www.domain.com/ and the URL should directly deliver content with a "200 OK" status, not issue a redirect.

I think that you should have a rewrite that pulls the data from the longer filepath when the short URL is requested, and then also have a redirect if the long URL is called, redirecting back to the root URL (a 301 redirect, that is).

itaine

6:53 am on Aug 17, 2007 (gmt 0)

10+ Year Member



thx for the reply.

Yes that would be ideal, however I'm using the Open-Realty framework which is generating the dynamic content at [domainname.com...]

I don't know how or if its possible to make that dynamic page render at [domainname.com...] --- then I wouldn't need the redirect and rewrite.

So my thinking is when the user goes to the [domainname.com...] redirect them to [domainname.com...] to show them that listing content and then rewrite the URL to a SEF [domainname.com...]

are you saying that doing so would not be good SEO practice?

this is what I'm starting with in my .htaccess

# SEARCH ENINGE FRIENDLY URLS FOR OR 2.0
<IfModule mod_php4.c>
php_value session.use_trans_sid 0
</IfModule>

Options +FollowSymLinks
rewriteEngine On
rewriteBase /

#Rewriterule ^index.html index.php
RewriteRule listing-([^-]*)-([0-9]*).html index.php?action=listingview&listingID=$2 [L]
RewriteRule page-([^-]*)-([0-9]*).html index.php?action=page_display&PageID=$2 [L]
RewriteRule search.html index.php?action=searchpage [L]
RewriteRule searchresults.html index.php?action=searchresults [L]
RewriteRule agents.html index.php?action=view_users [L]
RewriteRule view_favorites.html index.php?action=view_favorites [L]
RewriteRule calculator.html index.php?action=calculator&popup=yes [L]
RewriteRule saved_searches.html index.php?action=view_saved_searches [L]
RewriteRule listing_image_([0-9]*).html index.php?action=view_listing_image&image_id=$1 [L]
RewriteRule logout.html index.php?action=logout [L]
RewriteRule member_signup.html index.php?action=signup&type=member [L]
RewriteRule agent_signup.html index.php?action=signup&type=agent [L]
RewriteRule member_login.html index.php?action=member_login [L]
RewriteRule edit_profile_([0-9]*).html index.php?action=edit_profile&user_id=$1 [L]
# SEO Link for Agent Pages added in Open-Realty 2.4.1
RewriteRule agent-([^-]*)-([0-9]*).html index.php?action=view_user&user=$2 [L]

Can anyone tell me how to implement in a SEF manner?

Thx in advance
Taine

itaine

7:06 am on Aug 17, 2007 (gmt 0)

10+ Year Member



yes I meant to put this as the current state of the .htaccess file:

# SEARCH ENINGE FRIENDLY URLS FOR OR 2.0
<IfModule mod_php4.c>
php_value session.use_trans_sid 0
</IfModule>

Options +FollowSymLinks
rewriteEngine On
rewriteBase /

redirect to fix requests for non-canonical domain name
rewriteCond %{HTTP_HOST}!^www\.agent\.alpha
rewriteRule (.*) [agent.alpha...] [R=301,L]

# redirect root to dynamic content
RedirectMatch ^/$ /index.php?action=searchresults [L]

#----------------------------------------------------------#
#Rewriterule ^index.html index.php
RewriteRule listing-([^-]*)-([0-9]*).html index.php?action=listingview&listingID=$2 [L]
RewriteRule page-([^-]*)-([0-9]*).html index.php?action=page_display&PageID=$2 [L]
RewriteRule search.html index.php?action=searchpage [L]
RewriteRule searchresults.html index.php?action=searchresults [L]
RewriteRule agents.html index.php?action=view_users [L]
RewriteRule view_favorites.html index.php?action=view_favorites [L]
RewriteRule calculator.html index.php?action=calculator&popup=yes [L]
RewriteRule saved_searches.html index.php?action=view_saved_searches [L]
RewriteRule listing_image_([0-9]*).html index.php?action=view_listing_image&image_id=$1 [L]
RewriteRule logout.html index.php?action=logout [L]
RewriteRule member_signup.html index.php?action=signup&type=member [L]
RewriteRule agent_signup.html index.php?action=signup&type=agent [L]
RewriteRule member_login.html index.php?action=member_login [L]
RewriteRule edit_profile_([0-9]*).html index.php?action=edit_profile&user_id=$1 [L]
# SEO Link for Agent Pages added in Open-Realty 2.4.1
RewriteRule agent-([^-]*)-([0-9]*).html index.php?action=view_user&user=$2 [L]

EOF

Taine

jdMorgan

1:56 pm on Aug 17, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This line is incorrect in syntax -- It is mixing bits of mod_alias and mod_rewrite. Once corrected, this is actually the only line you need to implement SEF on the index page.

# redirect root to dynamic content
RedirectMatch ^/$ /index.php?action=searchresults [L]

Cleaning it up, we get:

# rewrite request for root URL-path to internal dynamic-content filepath
RewriteRule ^$ index.php?action=searchresults [L]

It's not clear why your original directive did not include the additional "pclass" parameter. Therefore, you may need to add it:

RewriteRule ^$ index.php?action=searchresults&pclass[]=1

The point is that the pattern on the left should match the URL (the link) published on your pages, while the substitution on the right should give the path and query string needed to access and invoke the script on your server.

Your other rules could do with a bit of improvement as well. They will run faster and have less potential to cause unexpected side-effects if they are properly anchored and if literal characters which are also defined as regex tokens within the patterns are properly escaped:

Example:


RewriteRule ^listing-([^-]+)-([0-9]+)\.html$ index.php?action=listingview&listingID=$2 [L]

I also changed the "*" quantifier tokens to "+" since it's unlikely you'd ever public a link with those fields completely-empty.

Jim

g1smd

3:51 pm on Aug 17, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



>> I don't know how or if its possible to make that dynamic page render at domainname.com/ --- then I wouldn't need the redirect and rewrite. <<

This is what a rewrite does. It takes the requested URL and internally translates it into the filepath on the server needed to fetch the content.

The user continues to see the URL they requested, NOT the internal filepath.

>> So my thinking is when the user goes to the domainname.com/ redirect them to domainname.com/index.php?action=searchresults&pclass[]=1&... to show them that listing content and then rewrite the URL to a SEF domainname.com/ <<

You have mixed the terminology up. It should be:

When the user requests www.domainname.com/ rewrite that so that content is pulled from /index.php?action=searchresults&pclass[]=1&... without exposing that information to the user.

If someone requests domainname.com/index.php?action=searchresults&pclass[]=1&..." force an external 301 redirect to domainname.com/ so that the dynamic URL cannot be indexed.

The code for a rewrite and a redirect is very similar. The redirect has an additional [R=301] to force an external redirect.

You'll need a 301 redirect to redirect requests for www.domainname.com/ over to domainname.com/ so that only domainname.com/ can be indexed.

itaine

12:12 am on Aug 19, 2007 (gmt 0)

10+ Year Member



Thank you both for your responses. Very very helpful!

Taine