ayok Posted September 11, 2008 Share Posted September 11, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/123842-htaccess-for-seo/ Share on other sites More sharing options...
Daniel0 Posted September 12, 2008 Share Posted September 12, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/123842-htaccess-for-seo/#findComment-639923 Share on other sites More sharing options...
ayok Posted September 12, 2008 Author Share Posted September 12, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/123842-htaccess-for-seo/#findComment-639996 Share on other sites More sharing options...
Daniel0 Posted September 12, 2008 Share Posted September 12, 2008 No, you should just use the rule I wrote. Then you should go to the former URL and it should act as though it was the latter. Quote Link to comment https://forums.phpfreaks.com/topic/123842-htaccess-for-seo/#findComment-640000 Share on other sites More sharing options...
ayok Posted September 12, 2008 Author Share Posted September 12, 2008 Hi Daniel0, I still don't see any effect. My .htaccess now looks like this: Options +FollowSymLinks RewriteEngine On RewriteBase / RewriteRule ^detail/id/(.*)/?$ detail.php?id=$1 What do you mean by former url? http://www.myweb.com/detail.php?id=234? ayok Quote Link to comment https://forums.phpfreaks.com/topic/123842-htaccess-for-seo/#findComment-640061 Share on other sites More sharing options...
Daniel0 Posted September 12, 2008 Share Posted September 12, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/123842-htaccess-for-seo/#findComment-640117 Share on other sites More sharing options...
ayok Posted September 12, 2008 Author Share Posted September 12, 2008 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)[/url] 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 Quote Link to comment https://forums.phpfreaks.com/topic/123842-htaccess-for-seo/#findComment-640171 Share on other sites More sharing options...
Daniel0 Posted September 12, 2008 Share Posted September 12, 2008 The rule is how it should be. I think you are using reverse terminology so to speak Doing it the other way around wouldn't make sense. Quote Link to comment https://forums.phpfreaks.com/topic/123842-htaccess-for-seo/#findComment-640181 Share on other sites More sharing options...
ayok Posted September 13, 2008 Author Share Posted September 13, 2008 But why it doesn't work as i expect? Quote Link to comment https://forums.phpfreaks.com/topic/123842-htaccess-for-seo/#findComment-640364 Share on other sites More sharing options...
Daniel0 Posted September 13, 2008 Share Posted September 13, 2008 I don't know. Have you checked that you've enabled the rewrite module? Are you sure you named the file correctly (i.e. .htaccess)? Have you set AllowOverride all in your httpd.conf to make it possible to use .htaccess files? Quote Link to comment https://forums.phpfreaks.com/topic/123842-htaccess-for-seo/#findComment-640374 Share on other sites More sharing options...
ayok Posted September 13, 2008 Author Share Posted September 13, 2008 Hmm.. i c.. I think I don't have access to change those. So do I have to ask the hosting to do that? Thank you for answering my questions so far. ayok Quote Link to comment https://forums.phpfreaks.com/topic/123842-htaccess-for-seo/#findComment-640382 Share on other sites More sharing options...
Daniel0 Posted September 13, 2008 Share Posted September 13, 2008 Yeah, asking them if you can use .htaccess files and if the mod_rewrite Apache module is enabled would be a good idea. Quote Link to comment https://forums.phpfreaks.com/topic/123842-htaccess-for-seo/#findComment-640384 Share on other sites More sharing options...
ayok Posted September 13, 2008 Author Share Posted September 13, 2008 Yeah, asking them if you can use .htaccess files and if the mod_rewrite Apache module is enabled would be a good idea. Ok I'll do that. Thanks a lot, Daniel0. ayok Quote Link to comment https://forums.phpfreaks.com/topic/123842-htaccess-for-seo/#findComment-640394 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.