URL Rewriting not working
Posted by ashras99, 03-11-2010, 01:41 PM On my apache server. My dynamic page url is like this.. www.xyz.com/job.php?id=2245 now i tried the following rule but not working, please tell me what's wrong. Options +FollowSymLinks RewriteEngine On RewriteBase / RewriteRule ^detailjob/([0-9]+)(.*)\.html$ job.php?id=$1 [NC,L] ** mod rewrite is enabled and other rules are working fine.
Posted by Driver01, 03-12-2010, 05:26 AM try it without the directory seperator i.e. I also removed the second pattern because you don't need it. This will give you a link of:
Posted by ashras99, 03-12-2010, 05:34 AM i tried this but also not working. RewriteRule ^detailjob-([0-9]+)\.html$ job.php?id=$1 [NC,L]
Posted by Driver01, 03-12-2010, 09:08 AM Well that should work lets try or try something simple to make sure mod-rewrite is working: create the appropriate files on the server to test.
Posted by ashras99, 03-12-2010, 09:27 AM second rule for test is working.... but actual rewriterule is not working and when RewriteEngine On is ON for other rules then not required to mention again.
Posted by Driver01, 03-12-2010, 09:53 AM Yes but this is the base directory right? you have other rules in different directories? or domains? I am presuming you have the domain xyz.com and in the base directory is a file job.php which uses a query string ?id=1234 which creates a url query string of http://www.xyz.com/job.php?id=1234, with a .htaccess file in the same directory using: RewriteEngine On RewriteBase / RewriteRule ^detailjob-([0-9]+)\.html$ job.php?id=$1 [NC] so when using a link http://www.xyz.com/detailjob-1234.html should resolve to the same as http://www.xyz.com/job.php?id=1234 without re-write. Last edited by Driver01; 03-12-2010 at 10:06 AM.
Posted by ashras99, 03-12-2010, 10:16 AM You are right but not tried the above way... and no intention of trying... because following mod_rewrite rule is not working. RewriteEngine On RewriteBase / RewriteRule ^detailjob-([0-9]+)\.html$ job.php?id=$1 [NC]
Posted by ashras99, 03-12-2010, 10:17 AM And my other rules are added in the base directory .htaccess and working fine.
Posted by Driver01, 03-12-2010, 10:21 AM why not just paste the .htaccess file here so I can see what is working?
Posted by ashras99, 03-12-2010, 10:27 AM well there is nothing wrong in my htaccess file, so i dont need to post here.
Posted by Driver01, 03-12-2010, 10:44 AM Ok well I have tested the exact same rewrite and it works for me, I only suggested that so I could compare a rule that is working with the one that isn't? btw when you say not working you mean you get the url doesn't exist error? all you are doing is rewriting "detailjob-($1).html" to "job.php?id=($1)" matching the id number and adding it. So by all intense purposes if the url "job.php?id=1234" is a valid then the re-write should work? Last edited by Driver01; 03-12-2010 at 10:56 AM.
Posted by ashras99, 03-12-2010, 11:06 AM when i say not working... that means when i access the url then that not converted into the http://www.xyz.com/detailjob-1234.html that always stays on http://www.xyz.com/job.php?id=1234 never get any url error.
Posted by Driver01, 03-12-2010, 11:48 AM ah...! Just to verify again, you are coding this uri into your documents: this when clicked gets rewritten by apache mod re-write according to the htaccess rules into: http://www.xyz.com/job.php?id=1234 and sent to that url not the other way around. The idea of re-write is for you to put nice uri into your html document replacing the long query strings and set apache mod re-write some rules and expressions to match if it matchs those expressions then it will send them to the destination which is provided i.e. expression to match: ^detailjob-([0-9]+)\.html$ destination url job.php?id=1234 Last edited by Driver01; 03-12-2010 at 11:51 AM.
Posted by ashras99, 03-12-2010, 11:53 AM i m accessing this in browser... http://www.xyz.com/job.php?id=1234 and this not changing to http://www.xyz.com/detailjob-1234.html
Posted by Driver01, 03-12-2010, 12:06 PM No it won't? you access this in the browser http://www.xyz.com/detailjob-1234.html and it will take you to http://www.xyz.com/job.php?id=1234. read the previous post, your getting confused in how re-writing works. Last edited by Driver01; 03-12-2010 at 12:11 PM.
Posted by ashras99, 03-12-2010, 12:19 PM my dynamic links take me to http://www.xyz.com/job.php?id=1234. so how they take me to http://www.xyz.com/detailjob-1234.html, how the url in browser and for search engine change?
Posted by Driver01, 03-12-2010, 12:35 PM with your mod re-write set as I suggested visit this link in the browser: http://www.xyz.com/detailjob-1234.html and it will take you to the same destination as your dynamic link without anyone knowing any different, thats mod re-writing. the nice link is just your dynamic link in disguise...its an alias
Posted by ashras99, 03-12-2010, 12:39 PM but if user and search keep seeing.. http://www.xyz.com/job.php?id=1234 then what's the use of that... then some rule also required to change the url display in browser.
Posted by Driver01, 03-12-2010, 12:50 PM No thats the point, they don't see the dynamic url at all, user or search engine, they see http://www.xyz.com/detailjob-1234.html. where-ever you use http://www.xyz.com/jobs.php?id=1234 in your document change it to the new link. BTW does it work now?
Posted by ashras99, 03-12-2010, 01:30 PM if i access this url http://www.xyz.com/detailjob-1234.html then loading the dynamic url... but only text... no CSS and images are loading. secondly, i have to make changes in the script because users currently seeing a dynamic link. http://www.xyz.com/job.php?id=1234
Posted by Driver01, 03-12-2010, 01:41 PM the css and images are just a path problem i.e. your not using the correct path, try full paths. Yes unfortunately you have to change the links in the script. I am glad its working for you, my pleasure.