[{"data":1,"prerenderedAt":242},["ShallowReactive",2],{"\u002Farticles\u002Fclean-urls":3},{"id":4,"title":5,"body":6,"createdAt":232,"description":233,"extension":234,"meta":235,"navigation":236,"path":237,"rawbody":238,"seo":239,"stem":240,"__hash__":241},"articles\u002Farticles\u002Fclean-urls.md","Clean URLS",{"type":7,"value":8,"toc":230},"minimark",[9,18,21,51,62,65,103,106,140,147,202,212,215,226],[10,11,12,13,17],"p",{},"I’d like to continue providing some simple tips on utilizing an .htaccess file to create some better URLs. Let’s be honest… no one wants to remember ",[14,15,16],"code",{},"domain.com\u002Fdisplay.php?room=kitchen&brand=cuisinart&name=ice-cream-maker",". The variables are nearly impossible to retain when you’re quickly browsing a site. With that said, you should take a few minutes and setup a RewriteRule to clean up that nasty URL.",[10,19,20],{},"You need to have the Rewrite Engine turned on for this to work:",[22,23,29],"pre",{"className":24,"code":25,"filename":26,"language":27,"meta":28,"style":28},"language-bash shiki shiki-themes github-light github-dark","# Turn On\nRewriteEngine On\n",".htaccess","bash","",[14,30,31,40],{"__ignoreMap":28},[32,33,36],"span",{"class":34,"line":35},"line",1,[32,37,39],{"class":38},"sJ8bj","# Turn On\n",[32,41,43,47],{"class":34,"line":42},2,[32,44,46],{"class":45},"sScJk","RewriteEngine",[32,48,50],{"class":49},"sZZnC"," On\n",[10,52,53,54,57,58,61],{},"Now, let’s start by cleaning up just one of those variables. Take just ",[14,55,56],{},"domain.com\u002Fdisplay.php?room=kitchen",", we can easily clean that URL to read as ",[14,59,60],{},"domain.com\u002Fkitchen",". Isn’t that much better?",[10,63,64],{},"Here’s the one liner to make that URL work:",[22,66,68],{"className":24,"code":67,"filename":26,"language":27,"meta":28,"style":28},"# Pretty URL (ex. \u002Froom)\nRewriteRule ^([A-Za-z0-9-]+)\u002F?$ display.php?room=$1 [NC,L]\n",[14,69,70,75],{"__ignoreMap":28},[32,71,72],{"class":34,"line":35},[32,73,74],{"class":38},"# Pretty URL (ex. \u002Froom)\n",[32,76,77,80,83,87,90,93,96,100],{"class":34,"line":42},[32,78,79],{"class":45},"RewriteRule",[32,81,82],{"class":49}," ^",[32,84,86],{"class":85},"sVt8B","([A-Za-z0-9-]+)",[32,88,89],{"class":49},"\u002F?",[32,91,92],{"class":85},"$ ",[32,94,95],{"class":49},"display.php?room=",[32,97,99],{"class":98},"s4XuR","$1",[32,101,102],{"class":85}," [NC,L]\n",[10,104,105],{},"This simple line is using a regular expression to match a URL to a specific file. Above we look for alphanumeric characters, as well as hyphens. Here are some other common patterns:",[22,107,109],{"className":24,"code":108,"filename":26,"language":27,"meta":28,"style":28},".* # Any Character\n[A-Za-z-]+ # Letters and Hyphens\n[0-9]+ # Numbers\n",[14,110,111,123,131],{"__ignoreMap":28},[32,112,113,117,120],{"class":34,"line":35},[32,114,116],{"class":115},"sj4cs",".",[32,118,119],{"class":49},"*",[32,121,122],{"class":38}," # Any Character\n",[32,124,125,128],{"class":34,"line":42},[32,126,127],{"class":85},"[A-Za-z-]+ ",[32,129,130],{"class":38},"# Letters and Hyphens\n",[32,132,134,137],{"class":34,"line":133},3,[32,135,136],{"class":85},"[0-9]+ ",[32,138,139],{"class":38},"# Numbers\n",[10,141,142,143,146],{},"Now, you’re probably wondering how to clean up a multiple-variable URL like at the beginning of this article. It’s easy as counting 1, 2, 3… All you have to do is keep increasing your ",[14,144,145],{},"$n"," in your rule, like so:",[22,148,150],{"className":24,"code":149,"filename":26,"language":27,"meta":28,"style":28},"# Pretty URL (ex. \u002Froom\u002Fbrand\u002Fname)\nRewriteRule ^([A-Za-z0-9-]+)\u002F([A-Za-z0-9-]+)\u002F([A-Za-z0-9-]+)\u002F?$ display.php?room=$1&brand=$2&name=$3 [NC,L]\n",[14,151,152,157],{"__ignoreMap":28},[32,153,154],{"class":34,"line":35},[32,155,156],{"class":38},"# Pretty URL (ex. \u002Froom\u002Fbrand\u002Fname)\n",[32,158,159,161,163,165,168,170,172,174,176,178,180,182,185,189,192,195,197,200],{"class":34,"line":42},[32,160,79],{"class":45},[32,162,82],{"class":49},[32,164,86],{"class":85},[32,166,167],{"class":49},"\u002F",[32,169,86],{"class":85},[32,171,167],{"class":49},[32,173,86],{"class":85},[32,175,89],{"class":49},[32,177,92],{"class":85},[32,179,95],{"class":49},[32,181,99],{"class":98},[32,183,184],{"class":85},"&brand",[32,186,188],{"class":187},"szBVR","=",[32,190,191],{"class":98},"$2",[32,193,194],{"class":85},"&name",[32,196,188],{"class":187},[32,198,199],{"class":98},"$3",[32,201,102],{"class":45},[10,203,204,205,207,208,211],{},"All your doing is creating a new pattern for each variable, then increasing your ",[14,206,145],{}," in the file name. After running this line in our .htaccess file, we end up with ",[14,209,210],{},"domain.com\u002Fkitchen\u002Fcuisinart\u002Fice-cream-maker",", a much improved URL.",[10,213,214],{},"Flags are also a vital part to rewriting URLs. Think of them as a rule to the rule. In the preceding examples, I’ve used NC,L as my only flags, meaning my rule is not case sensitive and if the pattern matches, stop processing. There are other rules that you can check out when experimenting with better URLs.",[10,216,217,218,225],{},"Utilizing the ",[219,220,224],"a",{"href":221,"rel":222},"http:\u002F\u002Fhttpd.apache.org\u002Fdocs\u002F2.0\u002Fmisc\u002Frewriteguide.html",[223],"nofollow","Apache mod_rewrite module",", you can create a much better URL scheme. Play around with what structures make the most sense to your site’s browsing experience.",[227,228,229],"style",{},"html pre.shiki code .sJ8bj, html code.shiki .sJ8bj{--shiki-default:#6A737D;--shiki-dark:#6A737D}html pre.shiki code .sScJk, html code.shiki .sScJk{--shiki-default:#6F42C1;--shiki-dark:#B392F0}html pre.shiki code .sZZnC, html code.shiki .sZZnC{--shiki-default:#032F62;--shiki-dark:#9ECBFF}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .sVt8B, html code.shiki .sVt8B{--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .s4XuR, html code.shiki .s4XuR{--shiki-default:#E36209;--shiki-dark:#FFAB70}html pre.shiki code .sj4cs, html code.shiki .sj4cs{--shiki-default:#005CC5;--shiki-dark:#79B8FF}html pre.shiki code .szBVR, html code.shiki .szBVR{--shiki-default:#D73A49;--shiki-dark:#F97583}",{"title":28,"searchDepth":42,"depth":42,"links":231},[],"2011\u002F01\u002F18","I’d like to continue providing some simple tips on utilizing an .htaccess file to create some better URLs. Let’s be honest… no one wants to remember domain.com\u002Fdisplay.php?room=kitchen&brand=cuisinart&name=ice-cream-maker. The variables are nearly impossible to retain when you’re quickly browsing a site. With that said, you should take a few minutes and setup a RewriteRule to clean up that nasty URL.","md",{},true,"\u002Farticles\u002Fclean-urls","---\ntitle: Clean URLS\ncreatedAt: 2011\u002F01\u002F18\n---\nI’d like to continue providing some simple tips on utilizing an .htaccess file to create some better URLs. Let’s be honest… no one wants to remember `domain.com\u002Fdisplay.php?room=kitchen&brand=cuisinart&name=ice-cream-maker`. The variables are nearly impossible to retain when you’re quickly browsing a site. With that said, you should take a few minutes and setup a RewriteRule to clean up that nasty URL.\n\nYou need to have the Rewrite Engine turned on for this to work:\n\n```bash[.htaccess]\n# Turn On\nRewriteEngine On\n```\n\nNow, let’s start by cleaning up just one of those variables. Take just `domain.com\u002Fdisplay.php?room=kitchen`, we can easily clean that URL to read as `domain.com\u002Fkitchen`. Isn’t that much better?\n\nHere’s the one liner to make that URL work:\n\n```bash[.htaccess]\n# Pretty URL (ex. \u002Froom)\nRewriteRule ^([A-Za-z0-9-]+)\u002F?$ display.php?room=$1 [NC,L]\n```\n\nThis simple line is using a regular expression to match a URL to a specific file. Above we look for alphanumeric characters, as well as hyphens. Here are some other common patterns:\n\n```bash[.htaccess]\n.* # Any Character\n[A-Za-z-]+ # Letters and Hyphens\n[0-9]+ # Numbers\n```\n\nNow, you’re probably wondering how to clean up a multiple-variable URL like at the beginning of this article. It’s easy as counting 1, 2, 3… All you have to do is keep increasing your `$n` in your rule, like so:\n\n```bash[.htaccess]\n# Pretty URL (ex. \u002Froom\u002Fbrand\u002Fname)\nRewriteRule ^([A-Za-z0-9-]+)\u002F([A-Za-z0-9-]+)\u002F([A-Za-z0-9-]+)\u002F?$ display.php?room=$1&brand=$2&name=$3 [NC,L]\n```\n\nAll your doing is creating a new pattern for each variable, then increasing your `$n` in the file name. After running this line in our .htaccess file, we end up with `domain.com\u002Fkitchen\u002Fcuisinart\u002Fice-cream-maker`, a much improved URL.\n\nFlags are also a vital part to rewriting URLs. Think of them as a rule to the rule. In the preceding examples, I’ve used NC,L as my only flags, meaning my rule is not case sensitive and if the pattern matches, stop processing. There are other rules that you can check out when experimenting with better URLs.\n\nUtilizing the [Apache mod_rewrite module](http:\u002F\u002Fhttpd.apache.org\u002Fdocs\u002F2.0\u002Fmisc\u002Frewriteguide.html), you can create a much better URL scheme. Play around with what structures make the most sense to your site’s browsing experience.\n",{"title":5,"description":233},"articles\u002Fclean-urls","VgmOFrohrkOXm_wk4SD0ZWC12qpZjuVT2QXzwVl_gE8",1794877726963]