Get It Today!
Including:- Rewrite flags
- Regular expression syntax
- Sample rules
Buy Now for just $2!
Overview
The mod_rewrite cheat sheet is a one-page reference sheet, listing flags for the RewriteRule and RewriteCond directives, list of server variables, a regular expression guide and several examples of common rules.
If you're new to URL rewriting with mod_rewrite, you might find my article on URL Rewriting for Beginners useful.
What's New?
There are a few small changes from the first version of the mod_rewrite Cheat Sheet (which you can still download if you prefer). The most obvious change may be that it now looks different. Hopefully it's now clearer and a little easier to find the information you're looking for.
Regular Expression Syntax
URL Rewriting with mod_rewrite depends a great deal upon a solid knowledge and understanding of regular expressions. The "RewriteRule" uses regular expressions in patterns extensively. This guide outlines the basic syntax of regular expression.
RewriteRule and RewriteCond Flags
Rewrite Rules in mod_rewrite can have flags appended to them, indicating to the server how the action described by the rule should be taken. For example, the 'L' flag tells the server not to process any more rules if the current rule is used.
Conditions in mod_rewrite can also have flags appended to them, and again these tell the server how to interpret the current condition. The "NC" flag indicates the condition is case-insensitive, and an "OR" flag between conditions tells the server that the following rule should be applied if any of the preceding conditions are true. The default in mod_rewrite is that, if a rule is preceded by a list of conditions, it should only be applied if all conditions are met.
Redirection Header Codes
When redirecting users with mod_rewrite, sometimes a status code must be sent back to the user. This status code is interpreted by the browser - sometimes it will mean the user is sent on to a new page, sometimes that they are shown a message. This section lists the most commonly used status codes with their meanings.
Example Rules
This section lists a few of the most situations mod_rewrite is used for, along with a rule to achieve the desired affect.
Server Variables
Sometimes it is necessary to rewrite URLs based upon variables like the referring URL or the browser being used. These variables can be used in mod_rewrite (including in the RewriteRule or RewriteCond sections), and this section lists the variables available.
Directives
mod_rewrite gives the server a series of instructions, called directives. For example, "RewriteEngine On" tells Apache that RewriteRules may be used and to interpret them if found. This section simply lists the directives used by mod_rewrite.
Other Formats
Get It Today!
Including:- Rewrite flags
- Regular expression syntax
- Sample rules
Buy Now for just $2!
The mod_rewrite Cheat Sheet is released under a Creative Commons License (Attribution, Non-Commercial, Share Alike).

131 Comments
Cool. This looks good. We use this as part of our web delivery framework. Will make a copy and pin it up for future reference.
Replies: #116.
#1, Olmec Sinclair, New Zealand, 2 July 2008. Reply to this.
I do tech support for a webhosting company. I use your mod_rewrite cheat sheets all the time.
#2, David Maas, United States, 9 July 2008. Reply to this.
Amazing! thanks a lot for this guide.
#3, Hari, Unknown, 14 July 2008. Reply to this.
This is a great reference guide. These cheat sheets do save our time and brain.. Have printed it out and its pretty useful! Thx very much!
#4, Bob, Unknown, 21 July 2008. Reply to this.
Thanks for this! Anything to make it easier to traverse mod_rewrite voodoo.
#5, James, United States, 22 July 2008. Reply to this.
Thanks everyone - you're all welcome. :)
#6, DaveChild, United Kingdom, 23 July 2008. Reply to this.
Hey,
Thanks... I too work for a hosting company and refer people to your site all the time. Thanks!
#7, Mike Piekarski, United States, 30 July 2008. Reply to this.
Thanks for the cheat sheet Dave. The flag list is particularly helpful. I started off with an example like your "Nice Looking URLs" in working with a recent site. I think many real world situations are going to need something more complex, or take the seo hit to put "category" and "page" in the url to key off of in a one line rewrite.
This example rewrites the urls for http://www.aslaninteractive.com
RewriteCond %{REQUEST_FILENAME}.cfm -f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^portfolio/([a-zA-Z0-9-_]+)$ /portfolio/$1.cfm [PT,L]
RewriteRule ^services/([a-zA-Z0-9-_]+)$ /services/$1.cfm [PT,L]
RewriteRule ^success_stories/([a-zA-Z0-9-_]+)$ /success_stories/$1.cfm [PT,L]
RewriteRule ^/?([a-zA-Z0-9-_]+)$ $1.cfm [PT,L]
#8, Matt MacDougall, Unknown, 10 August 2008. Reply to this.
I'm working on Wordpress and the client wants a spash screen (ugh) and I need to go to index.html if they go to the root of the website (url only, and no filename afterward) but for all else (any file, or directory) goes to index.php. I can't seem to figure out how to do it. I figured out how to map index.html to index.html (overcoming all going to index.php) but can't get the root to redirect. Any assistance would be greatly appreciated. The default WP .htaccess file with my mod:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/index.html$ index.html [C]
RewriteRule . /index.php [L]
</IfModule>
<IfModule mod_security.c>
<Files async-upload.php>
SecFilterEngine Off
SecFilterScanPOST Off
</Files>
</IfModule>
#9, Samantha, Unknown, 14 August 2008. Reply to this.
Hi,
Excellent tutorial. I will refer people to your site.
#10, Mezbaur Rahman, United Kingdom, 14 August 2008. Reply to this.
this sheet is awesome, help me so much
#11, Bali Web Developer, Indonesia, 17 August 2008. Reply to this.
Damm Good. It gives quick insight . Very Very Helpfull .
#12, Dilip Kumar, United States, 5 September 2008. Reply to this.
Sorry for my English, that it is not good, wanted to know if by means of rewrite it is possible to remove links broken from a Web, in fact is a vestibule of sales that takes links from another Web, therefore is impossible to annul them manually, places the Web to you in question, has 4 there but I do not put them not to make Spam, thanks
#13, Juan Francisco Segui, Unknown, 11 October 2008. Reply to this.
Hey I like the new additions to the cheat-sheet... It somewhat inspired me to document the various mod_rewrite variables at http://www.askapache.com/htaccess/mod_rewrite-variables-cheatsheet.html
I've found it really helpful while I'm messing with .htaccess stuff- I keep a printed copy on my desk!
#14, AskApache, United States, 11 October 2008. Reply to this.
Woahh good resource! Thx you very much...
#15, leoslab, Indonesia, 17 October 2008. Reply to this.
Very educative, indeed! I'm currently working on a script and I found this tutorial/guide very useful.
#16, Mexabet, Australia, 21 October 2008. Reply to this.
I need an cheat
#17, Victorboy, United States, 31 October 2008. Reply to this.
Useful. Thanks
#18, guatejon, Honduras, 6 November 2008. Reply to this.
Really great resource. I posted a link here to share your doc with other people: http://phireitup.blogspot.com/2008/11/modrewrite-cheat-sheet.html
#19, SaidK, Unknown, 6 November 2008. Reply to this.
This helped me a lot to crack the nut :)
thanks a lot my dear friend
keep the good work moving...
thnx again
#20, samil, Unknown, 14 November 2008. Reply to this.
Amazing! thanks a lot for this guide.
#21, Automation, Unknown, 15 November 2008. Reply to this.
Thank You very much. It's not easy for me, to understand the rewrite rules. But they are necessary for a webworker.
#22, Gerd-E., Germany, 27 November 2008. Reply to this.
Good mod_rewrite sheet, related to url-rewriting-for-beginners in your article.
Very useful ...
#23, Myea Amelia, Indonesia, 28 November 2008. Reply to this.
Amazing effort! I am wondering how to use mod_rewrite with Rails mongrel?
Thanks!
#24, Alan Murary, Unknown, 11 December 2008. Reply to this.
This is an awesome site.
#25, J.T., Jordan, 11 December 2008. Reply to this.
Thank you very much for this valuable sheet.
Regards.
#26, Maksin, Unknown, 24 December 2008. Reply to this.
Nothing like cheatin' to get something done faster!
#27, Rimian, Australia, 8 January 2009. Reply to this.
Thank you very much for this very helpful cheat sheets!
#28, Saeed, Unknown, 12 January 2009. Reply to this.
Excellent! mod_rewrite rules
#29, ed neville, United Kingdom, 12 January 2009. Reply to this.
this example not work <IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/index.html$ index.html [C]
RewriteRule . /index.php [L]
</IfModule>
<IfModule mod_security.c>
<Files async-upload.php>
SecFilterEngine Off
SecFilterScanPOST Off
</Files>
</IfModule>
#30, Luiss, colombia, 14 January 2009. Reply to this.
I was looking for a summary like that, many thanks!
#31, Alex from Nürnberg, Unknown, 29 January 2009. Reply to this.
Hi,
I am using mod_rewrite in my web site and getting following issue.
My root directory path
/xxx/yyy/public_html/
All my files website present in ?official? folder (i-e) /xxx/yyy/public_html/official/
.htaccess file present in root directory (i-e) /xxx/yyy/public_html/
Script present in .htaccess file.
RewriteEngine On # Turn on the rewriting engine
RewriteRule ^official/browse/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$ official/index.php?do=browse&s=$1&ss=$2 [NC,L] # Process browse requests
RewriteRule ^official/browse/([A-Za-z0-9-]+)/?$ official/index.php?do=browse&s=$1 [NC,L] # Process browse requests
RewriteRule ^official/([A-Za-z-]+)/?$ official/index.php?do=$1 [NC,L] # Process product requests
Script present in browse.php
<a href="index.php?do=browse&s=<?php echo $sect['id']; ?>&ss=<?php echo $ssect['id']; ?>"><strong><?php echo $ssect['subname']; ?></strong></a>
My issue
At first visit of browse page it works fine
(i-e) http://www.mydomain.net/official/browse/1/1/
If I click another section in browse page, it shows ?The page cannot be found? because of /browse/1/2/ added after /browse/1/1/
(i-e) http://www.mydomain.net/official/browse/1/1/browse/1/2/
Please give your suggestion to over come this problem and waiting for your valuable reply.
Thanks in advance.
Manikandan.S
#32, Manikandan, Unknown, 29 January 2009. Reply to this.
Some great information, another good site that I have found that may be of interest to your users is this site that has a mod rewrite generator: http://www.generateit.net/mod-rewrite/
#33, Dave Simpson, Unknown, 8 February 2009. Reply to this.
hey, this cheat is so awesome. many thanks!
#34, hal?, turkey, 14 February 2009. Reply to this.
That's what I really wanted, all info in one place! This is really useful.
#35, Abhijeet Pathak, India, 21 February 2009. Reply to this.
very good guia
#36, Bilaz, Brazil, 1 March 2009. Reply to this.
slightly confussed on a few things! and with my eye sight chances are I've miss read something somewhere.
RewriteEngine On
RewriteRule ^([A-Za-z0-9-]+)/?$ index.php?pagename=$1
gives me the nice urls.
but I have a form which resides in /contact/ and all links are setup as mysite
mysite/about/
and so on and when it gets to mysite/contact/
it tries to find the pagename from the database. how do I get to to redirect to that folder so it will pick the form up?
As I sida I think i've missed something somewhere. hope someone is kind enough to HELP.
Regards
Mally
#37, mally, United Kingdom, 2 March 2009. Reply to this.
Hey! this help me so much ! tanks!
#38, Vini, Brazil, 4 March 2009. Reply to this.
Thanks for the article.
I used to mod_rewrite in .htaccess files im my site http://www.otimizacao-de-websites.com , but using cheat sheet to rewrite is great new to me!
#39, Marcos, Brazil, 12 March 2009. Reply to this.
this helped me a lot. thanks.
#40, web dizayn, Unknown, 13 March 2009. Reply to this.
phew! just what i was looking for... bookmarked :)
#41, Mr. G, Unknown, 24 March 2009. Reply to this.
Hej Thank you for your great work. This will help me alot.. Printed on A3+ :)
#42, Michael, Kosovo, 2 April 2009. Reply to this.
Thanks for this! I got what I was looking for in 1 minute!
#43, Emprestimo Pessoal, Germany, 9 April 2009. Reply to this.
Nice! Glad you put it into a nice printable form. Will have to get this laminated.
#44, Tim Sabulis, Unknown, 14 April 2009. Reply to this.
Yeah, that was what i searching for. Now it works fine on my site, Thank you.
#45, Barney, Unknown, 14 May 2009. Reply to this.
Good resource!
#46, Martin, Uruguay, 18 May 2009. Reply to this.
Good post!
Liked and back other time
indicate to my friends
cya!
#47, Moda, Unknown, 26 May 2009. Reply to this.
Great, i`m still working on a htaccess file. Now i can work faster. I`m a beginner with mod rewrite but i`m geting better.
#48, Auspuff, Germany, 8 June 2009. Reply to this.
Wow. What a great post!!! I'm downloading your cheatsheat now. Thanks for share it with us.
#49, Ivan Kristianto, Australia, 28 June 2009. Reply to this.
Hey, Thank you very much for this very helpful info!
#50, Kubotan, Unknown, 29 June 2009. Reply to this.
thanks for sharing this, I was looking for some cheat sheet like this.
keep on the good work. thank you.
#51, Veyton, Unknown, 7 July 2009. Reply to this.
This is awesome, I just downloaded you regular Expression sheet. These are very helpful!
#52, Dwayne, Shasta Lake CA, 21 July 2009. Reply to this.
Super guide!
#53, Trockenfutter, Germany, 22 July 2009. Reply to this.
Amazing! thanks a lot for this guide. Very helpfull, good work.
#54, Haarentfernung, Germany, 25 July 2009. Reply to this.
Yes a good guide
#55, Geldanlage-Vergleich, Germany, 26 July 2009. Reply to this.
This is an excellent overview but I'd like to make just a couple of recommendations:
1. The No Case flag should RARELY be used in a RewriteRule - it's purpose is to match case INsensitive characters such as those in the {HTTP_HOST}. If they're used in a RewriteRule to capture in an Apache $n variable, the receiving script must then convert the case to be usable. Think about WHO is creating the URI for the mod_rewrite to convert and ask WHY create a LOT more work for yourself.
2. The Last flag ... and the start anchor difference in the two versions of Apache (^/ for Apache 1.x, ^ for Apache 2.x, ^/? for both). You've shown only Apache 2's version with no directions for change for Apache 1.x.
If you ever feel the need to go to a second page, examples would help people learn a bit more about how these code snippets are used. I have a few at the bottom of the horribly long tutorial at http://datakoncepts.com/seo.
#56, DK, New Zealand, 4 August 2009. Reply to this.
A very useful cheat sheet.
#57, rinoplastia, Spain, 13 August 2009. Reply to this.
I think mod rewrite is really complecated. Thanks for this article.
#58, haister, Unknown, 13 August 2009. Reply to this.
this seems to be very usefull. Thanks for sharing this.
#59, Miyuki, Germany, 20 August 2009. Reply to this.
Great work! Very nice site.
#60, Geberstange, Germany, 26 August 2009. Reply to this.
Thank for sharing this excellent mod_rewrite guide!
#61, Spachtel, Germany, 1 September 2009. Reply to this.
Thank you. It's not easy for me, to understand the rewrite rules. But they are necessary for a webworker.
cu
#62, Chris Trick, Germany, 4 September 2009. Reply to this.
A nice work, like your other cheat sheets. A big thanks for sharing thar guide from Kinderbuch.
#63, Kinderbuch, Unknown, 7 September 2009. Reply to this.
Hi,
The mod rewrite rule works perfectly. The page redirect by getting the variable and uses it right. but it does not pint the actual url in address bar
http://www.divinequran.com/koran/1-Al-Fatiha.html
It has to display the above url in the address bar, Instead of it displays the rewrite code as it is. I have used option L but it doesnot works.
#64, mathguy, India, 28 September 2009. Reply to this.
Ooough.. little bit confuse...
#65, Fisika SMA, Indonesia, 5 October 2009. Reply to this.
Super brilliant reference book! With the help of the "cheat sheet" can I save my various data faster. The best example is the "flag list"
Thanks for the great cheat sheet, Dave!
cu
#66, Andreas, Unknown, 7 October 2009. Reply to this.
I'm glad I found this cheat sheet. It has been helpful to me while rewriting the dynamically-generated URLs of my photo gallery. Thanks, Dave.
#67, PHP Gallery, Australia, 14 October 2009. Reply to this.
This is one of the best mod rewrite cheat sheets I've found.
#68, Cesc Fabregas, Australia, 25 October 2009. Reply to this.
Even with all the articles and tutorials I've seen on the net, Mod_Rewrite is still a voodoo. I hope this cheat sheet will help to rewrite my URLs.
#69, Kyle, Ireland, 25 October 2009. Reply to this.
This is a great reference guide. These cheat sheets do save our time and brain.. Have printed it out and its pretty useful! Thx very much!
#70, Fussmatten, Germany, 27 October 2009. Reply to this.
Great reference-sheet, which saves a lot of time. Thanks for sharing it, it's one of the best cheat-sheets that are in the net.
#71, Weihnachtsgeschenke, Germany, 9 November 2009. Reply to this.
Hi guys,
I'm a bit stuck... I'm moving articles that were published using a custom CMS and contained capitalized links to running wordpress as CMS.
Now WP doesn't allow capitalization in links, but there are links all over the net pointing to my articles.
Is there a rewrite rule that enable me to say ignore the case of any link coming in to the directory /articles and make it all lower case?
Can I also include to ignore the ending, ie .html, .php, ect...
Thanks for your help!
Veit
#72, Veit, Australia, 20 November 2009. Reply to this.
Thank You very much for that great sheet. It's really hard for me, to understand that rewrite rules. But from time to time I really need them.
#73, Birger, Unknown, 20 November 2009. Reply to this.
Thanks a lot for this guide.
#74, Roman, Germany, 8 December 2009. Reply to this.
Thanks for the effort and time you put in to make these sheets available. They make things a lot easier.
Andy :-)
#75, Andy Kuiper, Canada, 17 December 2009. Reply to this.
Thank for sharing this excellent mod_rewrite guide
#76, Angelreisen, Germany, 23 December 2009. Reply to this.
Nice guide, I also used this instructions on my website: <a href="www.nanunikokoritu.org">www.nanunikokoritu.org</a>
#77, Erik C., Brazil, 23 December 2009. Reply to this.
Really useful stuff.
Cool and handy rewrite cheat sheet.
Thank you.
#78, wiserx, 24 December 2009. Reply to this.
hi Dave.
can see you've heard it all before here, but we have been periodically struggling with various htaccess needs on and off for years now, wish i'd seen these before..
thanks for posting and regards from Ibiza
kev grant
#79, kev grant, ibiza, 17 January 2010. Reply to this.
Mod rewrite is a very difticult task. These sheets helps much.
#80, Kreditvergleich Wissen, Germany, 19 January 2010. Reply to this.
Please give your suggestion to over come this problem and waiting for your valuable reply.
Thank you
#81, Wärmepumpe, Germany, 7 February 2010. Reply to this.
Please give your suggestion to over come this problem and waiting for your valuable reply.
Thank you
#82, Wärmepumpe, Germany, 7 February 2010. Reply to this.
Please give your suggestion to over come this problem and waiting for your valuable reply.
Thank you
#83, Wärmepumpe, Germany, 7 February 2010. Reply to this.
I am running a blog site that was converted over from a static html site. I have an htaccess file in place to 1) rewrite posts, 2) redirect old pages to new pages.
My problem is that everything works fine except for simply redirecting www.mydomain.com/index.html to www.mydomain.com/
Here is what my htaccess file looks like, can you help me fix it? I wonder if it has something to do with the first rewrite rule for index.php?
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
RewriteRule ^index\.html$ http://www.mydomain.com/ [R,L] - This is the one that does not work
RewriteRule ^page1\.html$ http://www.mydomain.com/page1/ [R,L]
RewriteRule ^page2\.html$ http://www.mydomain.com/ [R,L]
RewriteRule ^page3\.html$ http://www.mydomain.com/page3/ [R,L]
RewriteRule ^page4\.html$ http://www.mydomain.com/page4/ [R,L]
RewriteRule ^page5\.html$ http://www.mydomain.com/page5/ [R,L]
#84, Atlanta Web Design, 8 February 2010. Reply to this.
Try the following instead:
RewriteRule ^(.*/)?index\.([a-zA-Z0-9]{3,4})$ /$1 [R=301,L]
This will send index.php or index.html to the domain root.
You should also reverse the order of the two code blocks, so that all of the redirects are done before your rewrites to wordpress. Otherwise, wordpress URLs will not benefit from the "fix-ups" you are doing with your redirects. This is likely the reason that your code isn't working.
#85, Mark Inns, UK, 10 February 2010. Reply to this.
mod_rewrite - use this very often
#86, fotografia ?lubna Katowice, poland, 20 February 2010. Reply to this.
Nie place here Thanks
#87, lebron James, poland, 20 February 2010. Reply to this.
Use this in my site. Very nice
#88, fotografia ?lubna, poland, 20 February 2010. Reply to this.
Thanks for post man.
#89, Contabilidade em Geral, Brasil, 21 February 2010. Reply to this.
Congratulations!!!
#90, Acompanhantes em BH, Brasil, 21 February 2010. Reply to this.
Good post!
Liked and back other time
indicate to my friends
cya!
#91, Marmoraria, Brasil, 21 February 2010. Reply to this.
Thank u so much, great ide. cool ;)
#92, aangbiz, 25 February 2010. Reply to this.
i love this place!
#93, psycholog online, pol, 15 March 2010. Reply to this.
i agree.. great place!
#94, fotograf ?lubny Kraków, pol, 15 March 2010. Reply to this.
very usefull thx
#95, brian, berlin, 19 March 2010. Reply to this.
good idea, i think my seo blog are now better with this cheat
#96, maidtool, 20 March 2010. Reply to this.
Thanks for that sheet, those mod_rewrite is not easy...
#97, Bodenmais, Bayerischer Wald, 7 April 2010. Reply to this.
Very educative, indeed! I'm currently working on a script and I found this tutorial/guide very useful.
#98, SEO, Belgium, 5 May 2010. Reply to this.
I think Creative Commons Licenses are greats. Thx for the script, I'll try it !!
#99, tshirt lover, france, 11 May 2010. Reply to this.
Maybe there should be a one-click link to the image so that we can skip the "you are downloading a file, well done" page? Or perhaps send the MIME (assuming that's the problem here) header so that the download could be opened in the browser instead of a "what do you want to do with it" dialogue. This would work maybe?
#100, printplace, UK, 20 May 2010. Reply to this.
Thanks again for this, I will definetly be refering to this for mod source code! Thank you!
#101, Coder, USA, 8 July 2010. Reply to this.
Hi, I am working on the rewritemap and rewriterule for my website. actually requirement is like i have one website whose address is http://www.myside1.com now since i am going to retire this website so i need to redirect most of the pages to new website. i want to use map file for this. i have created this mapping file where i want to keep maping like /folder1/page1.html http://newwebsite.com/content/view/hello.html in this way i want to use the redirection. i dont want to hardcode the each redirect rule. I can have /folder2/page1.html also. Could you please help me to have the correct rule.
#102, Himanshu, India, 9 July 2010. Reply to this.
Nice cheat sheet, that mod_rewrite is an essential for online shops!
#103, Autobatterie - Shop, Germany, 13 July 2010. Reply to this.
Nice work, like your other cheat sheets.
Though I'm a little bit confused with this one.
#104, brennstoffe, Austria, 27 July 2010. Reply to this.
I tried mod_rewrite until I drove crazy, but first when I used Wordpress, it woks. I will never understand this thing!
#105, Manu (Haarentfernung), Germany, 31 July 2010. Reply to this.
I have a windows server and use appserv and had a heck of a time figuring out mod rewrite.
#106, deleted, usa, 9 August 2010. Reply to this.
Really useful stuff.
Cool and handy rewrite cheat sheet.
Thank you.
#107, Torpedo gratis, USA, 21 August 2010. Reply to this.
Mod rewrite is a very interesting theme for me. I will look through your other article to get more information. Thank by now
#108, deleted, Germany, 1 September 2010. Reply to this.
Very good... Thanks
#109, Ruben Zevallos Jr., Brazil, 3 October 2010. Reply to this.
This is a great reference guide. These cheat sheets do save our time and brain.. Have printed it out and its pretty useful! Thx very much!
#110, Baufinanzierung, 13 October 2010. Reply to this.
The list with the flags is particularly helpful, many thanks for this great work Dave.
#111, Stephan Vogel, Germany, 14 October 2010. Reply to this.
Hi everyone,
Dave thanks for this hints, I look up a solution for one “robots.txt” problem, mean your following would function:
# domain.com/robots.txt to domain.com/new_robots.txt
RewriteRule ^robots.txt$ new_robots.txt [R,NC,L]
???
#112, Andre Behncke, Germany, 16 October 2010. Reply to this.
Dave, many thanks for this helpful hints.
@ Andre Behncke,
Why not that should function, but why you want rewrite robots.txt?
#113, Achim Detjen, Germany, 17 October 2010. Reply to this.
@Andre Behncke, Achim Detjen
I have this in .htaccess
RewriteCond %{http_host} ^www.xyz.de
RewriteRule ^robots.txt$ /xyz_robots.txt [L]
I separated also 2 of domain without vhost only with a browser sniffing (browser switch).
@Dave
many thanks for helpful hints
#114, Autolackierer, Germany, 26 October 2010. Reply to this.
Great post I was able to use this to move my entire wordpress site to drupal!
#115, -, US, 14 January 2011. Reply to this.
I am migrating a domain to a new website:
I need to point: http://news.flightmapping.com/
anyone got any ideas how....
http://www.flightmapping.com/?page_id=16426
Help much appreciated
Miranda
#116, Miranda de Freston, UK, 3 March 2011. Reply to this.
Hi,
I am running a LAMP website. For some reason some of my rewrites are not working. I enabled rewrite logging and below is the output of something the erroneous rewrites. My problem is that this "null" string is being written to the end of the rewrite, any idea why? Any help is greatly appreciated!
127.0.0.1 - - [07/Mar/2011:04:23:41 --0600]
[localhost/sid#21299650][rid#21486270/initial] (3) [perdir
/var/www/LabOrders/] add path info postfix:
/var/www/LabOrders/NewLabOrder -> /var/www/LabOrders/NewLabOrder/null
127.0.0.1 - - [07/Mar/2011:04:23:41 --0600]
[localhost/sid#21299650][rid#21486270/initial] (3) [perdir
/var/www/LabOrders/] strip per-dir prefix:
/var/www/LabOrders/NewLabOrder/null -> NewLabOrder/null
#117, matthew a, usa, 8 March 2011. Reply to this.
hi. I you can simple change your whole website theme through just this rewrite rule
by this
RewriteCond %{http_host} ^([^.]+)\.test.com [NC]
RewriteRule ^(images|css)/(.+)$ themes/2/$1/$2 [L]
for more info you can visit this
http://developer99.blogspot.com/2011/07/changing-your-website-theme-thorugh.html
#118, developer99, Pakistan, 26 July 2011. Reply to this.
I'm glad I found this cheat sheet. It has been helpful to me while rewriting the dynamically-generated URLs of my photo gallery. Thanks, Divan
#119, Divan, Brazil, 6 August 2011. Reply to this.
Thanks for sharing this cheat sheet. It´s just i was searching for.
Very useful!!
#120, pingu, spain, 12 August 2011. Reply to this.
Stupid 301 redirect. I have been reading the wrong thing for so long. Thank you for correcting me and showing me this. I really wish that I came across this first instead of those silly forums.
#121, michaelbarton, Australia, 29 February 2012. Reply to this.
This is awesome, and it was really glad to google this cheat sheet. I'm novice for htaccess and now have some knowlage about htacess as well as mod_rewrite. Keep posting
Thanks
#122, Bandarawela, Sri Lanka, 22 March 2012. Reply to this.
Thanks for this cheat sheet........
#123, Anoop, india, 26 March 2012. Reply to this.
This Mod_rewrite cheat sheet has been very instrumental in helping me to learn how to make my web pages search engine friendly.
#124, Justin, Thailand, 27 May 2012. Reply to this.
Thanks Dave for sharing the excellent cheat sheets.
#125, abdul, IE, 20 June 2012. Reply to this.
Hi all. Please note that the cheat sheet is still free, if you prefer, from Cheatography - the link is at the top of the page.
#126, DaveChild, United Kingdom, 24 January 2013. Reply to this.
I do love a cheat sheet me!
Now one for mod_rewrite is excatly what I need.
#127, David, UK, 6 March 2013. Reply to this.
Thanks for the sheet. Really handy item. I am hoping someone can help me here, I've spent days on this and still can't a) get an answer b) find a solution.
Options +FollowSymLinks
RewriteEngine on
rewritecond %{http_host} ^localhost
RewriteCond %{REQUEST_URI} /jw-ver3/testurl/url [NC]
RewriteRule testurl/url url1.htm [DPI,L]
Works first time and I get the proper url
http://localhost/jw-ver3/testurl/url1but clicking again produces http://localhost/jw-ver3/testurl/testurl/url1 and ad infinitum...
I've literally spent days trying to find an answer on the net, I've found people with the same problem but no answer. I've installed apache 2.2.22 as well and tried the DPI flag but nothing works.
I tried the simple example on your cheat sheet - same problem (RewriteRule ^([A-Za-z0-9-]+)/?$ url1.htm [DPI,L])
I'm quickly losing the will to live with this one.
#128, Jim Johnstone, UK, 30 April 2013. Reply to this.
Have to say, whilst I love the content, I'm disappointed that the sheet is a JPG packaged as PDF. I'd appreciate being able to copy paste, and some resolution independence.
Here's hoping there's an update. (Not sure I'd buy it twice, to be honest).
#129, Tim Osborn, Australia, 15 May 2013. Reply to this.
@jim - i think.... the rule is being applied recursively because you've ommitted the carat ^testurl which says 'match testurl when it occurs at the beginning of the string'.
Try adding a ^ like so:
RewriteCond %{REQUEST_URI} /jw-ver3/testurl/url [NC]
RewriteRule ^testurl/url url1.htm [DPI,L]
#130, Tim Osborn, Australia, 15 May 2013. Reply to this.
Hi Tim, thanks for the reply. Finally tracked it down to the rel links. Moved everything to the root directory and played around with the slashes until it worked (combination of the links on the page and the rewriterule in .htaccess).
#131, Jim, UK, 21 May 2013. Reply to this.