Jump to content

htaccess for SEO


ayok

Recommended Posts

Hi,

I'm trying to get a friendly url using the htaccess file, as followed:

Options +FollowSymLinks
RewriteEngine on
RewriteRule ^detail/id/(.*)/ detail.php?id=$1
RewriteRule ^detail/id/(.*) detail.php?id=$1

I expect to get an url like http://www.myweb.com/detail/id/234 from the original url http://www.myweb.com/detail.php?id=234. However I've got two problem doing this experiment.

First, for some server I am not able to upload .htaccess file. Even i tried to upload it as htaccess.txt.

Second, I finally able to upload to other server, but it just doesn't work.. I still see http://www.myweb.com/detail.php?id=234 on url bar.

 

Could anyone help me with this?

 

thanks,

ayok

Link to comment
https://forums.phpfreaks.com/topic/123842-htaccess-for-seo/
Share on other sites

I think you've misunderstood it... Your rewrite will make http://www.myweb.com/detail/id/234 act as though it was in fact http://www.myweb.com/detail.php?id=234, so if you enter the latter URL then that's what you'll see. Also, you can make a slight optimization in your rewrites: Instead of having

RewriteRule ^detail/id/(.*)/ detail.php?id=$1
RewriteRule ^detail/id/(.*) detail.php?id=$1

then you can just have

RewriteRule ^detail/id/(.*)/?$ detail.php?id=$1

The question mark makes the preceding character optional, and the dollar sign matches "end of line".

 

I'll also move this to the Apache mod_rewrite board seeing as it's not SEO you have trouble with, but rather configuring Apache.

Link to comment
https://forums.phpfreaks.com/topic/123842-htaccess-for-seo/#findComment-639923
Share on other sites

Thanks Daniel, I didn't know that there is specific forum about this. I am new with configuring .htaccess. I was looking for a solution in seo, and I find .htaccess solution. Basically what i'm going to do is to rewrite the url become seo friendly. I try this way, but end up with a problem.

 

I think you've misunderstood it... Your rewrite will make http://www.myweb.com/detail/id/234 act as though it was in fact http://www.myweb.com/detail.php?id=234, so if you enter the latter URL then that's what you'll see.

 

I don't really understand what you mean.. So I should switch it like:

RewriteRule ^detail.php?id=$1?$ detail/id/(.*)/

?

 

ayok

Link to comment
https://forums.phpfreaks.com/topic/123842-htaccess-for-seo/#findComment-639996
Share on other sites

Uhm... when I mention the two URLs http://www.myweb.com/detail/id/234 and http://www.myweb.com/detail.php?id=234 then http://www.myweb.com/detail/id/234 will be the former whereas http://www.myweb.com/detail.php?id=234 will be the latter.

See: http://dictionary.reference.com/browse/former (no. 4) and http://dictionary.reference.com/browse/latter (no. 1)

 

When you have the rule:

RewriteRule ^detail/id/(.*)/?$ detail.php?id=$1

Then any URL that matches the regex pattern ^detail/id/(.*)/?$ will be rewritten (you could call it forwarding without changing the URL) to detail.php?id=$1.

 

You might want to check out the following things:

http://httpd.apache.org/docs/2.2/rewrite/

http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html

 

Also, basic knowledge of regex (regular expressions) is required as it's what the rewriting rules are essentially based on. In your example, ^detail/id/(.*)/?$ means:

Match start of line, followed by detail followed by a slash, followed by any character 0-∞ times, optionally followed by a slash, following end of line.
The things in parentheses will be stored in back references (.*) and is accessed via e.g. $1 later.
Link to comment
https://forums.phpfreaks.com/topic/123842-htaccess-for-seo/#findComment-640117
Share on other sites

 

:) Thank you for being so patient to explain me about "former" and "latter".

 

When you have the rule:

RewriteRule ^detail/id/(.*)/?$ detail.php?id=$1

Then any URL that matches the regex pattern ^detail/id/(.*)/?$ will be rewritten (you could call it forwarding without changing the URL) to detail.php?id=$1.

 

Uh? I think what I want is the other way around. I want detail.php?id=234 become detail/id/234. So my code is wrong? How do I change it then? My code now:

RewriteRule ^detail/product/([0-9]+)/?$ detail.php?id=$1

 

thanks,

ayok

Link to comment
https://forums.phpfreaks.com/topic/123842-htaccess-for-seo/#findComment-640171
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.