.Htaccess rewrites, Mod_Rewrite Tricks and Tips
« Blocking Bad Bots and Scrapers with .htaccessUndetectable Sniffing On Ethernet »
Mod_Rewrite Tips and Tricks are lot of .htaccess rewrite examples that show specific uses for creating .htaccess rewrites to do all kinds of cool and profitable stuff for your site. Htaccess Rewrites are enabled by using the Apache module mod_rewrite, which is one of the most powerful Apache modules and features availale. Htaccess Rewrites through mod_rewrite provide the special ability to Rewrite requests internally as well as Redirect request externally.
When the url in your browser’s location bar stays the same for a request it is an internal rewrite, when the url changes an external redirection is taking place. This is one of the first, and one of the biggest mental-blocks people have when learning about mod_rewrite… But I have a secret weapon for you to use, a new discovery from years of research that makes learning mod_rewrite drastically quicker and easier. It truly does or I wouldn’t be saying so in the introduction of this article.
Despite the tons of examples and docs, mod_rewrite is voodoo.
Damned cool voodoo, but still voodoo.
– Brian Moore
Note: After years of fighting to learn my way through rewriting urls with mod_rewrite, I finally had a breakthrough and found a way to outsmart the difficulty of mod_rewrite that I just couldn’t seem to master. The Mod_Rewrite RewriteCond/RewriteRule Variable Value Cheatsheet is the one-of-a-kind tool that changed the game for me and made mod_rewriting no-harder than anything else.
So keep that mod_rewrite reference bookmarked and you will be able to figure out any RewriteRule or RewriteCond, an amazing feat considering it took me a LONG time to figure this stuff out on my own. But that was before the craziness, one of the most challenging and productive .htaccess experiments I’ve done… An experiment so ILL it’s sick like a diamond disease on your wrist! $$$. That mod_rewrite experiment/tutorial was the culmination of many different advanced mod_rewrite experiments I had done in the past and included most of my very best .htaccess tricks. With the cheatsheet it’s no longer Voodoo.. Its just what you do. Now lets dig in!
If you really want to take a look, check out the mod_rewrite.c and mod_rewrite.h files.
Be aware that mod_rewrite (RewriteRule, RewriteBase, and RewriteCond) code is executed for each and every HTTP request that accesses a file in or below the directory where the code resides, so it’s always good to limit the code to certain circumstances if readily identifiable.
For example, to limit the next 5 RewriteRules to only be applied to .html and .php files, you can use the following code, which tests if the url does not end in .html or .php and if it doesn’t, it will skip the next 5 RewriteRules.
RewriteRule !\.(html|php)$ - [S=5] RewriteRule ^.*-(vf12|vf13|vf5|vf35|vf1|vf10|vf33|vf8).+$ - [S=1]
Options +FollowSymLinks RewriteEngine On RewriteBase /
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\.askapache\.com$ [NC]
RewriteRule ^(.*)$ http://www.askapache.com/$1 [R=301,L]
Sometimes your rewrites cause infinite loops, stop it with one of these rewrite code snippets.
RewriteCond %{REQUEST_URI} ^/(stats/|missing\.html|failed_auth\.html|error/).* [NC]
RewriteRule .* - [L]
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule .* - [L]
This is probably my favorite, and I use it on every site I work on. It allows me to update my javascript and css files in my visitors cache’s simply by naming them differently in the html, on the server they stay the same name. This rewrites all files for /zap/j/anything-anynumber.js to /zap/j/anything.js and /zap/c/anything-anynumber.css to /zap/c/anything.css
RewriteRule ^zap/(j|c)/([a-z]+)-([0-9]+)\.(js|css)$ /zap/$1/$2.$4 [L]
When you use flash on your site and you properly supply a link to download flash that shows up for non-flash aware browsers, it is nice to use a shortcut to keep your code clean and your external links to a minimum. This code allows me to link to site.com/getflash/ for non-flash aware browsers.
RewriteRule ^getflash/?$ http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash [NC,L,R=307]
On many sites, the page will be displayed for both page.html and page.html?anything=anything, which hurts your SEO with duplicate content. An easy way to fix this issue is to redirect external requests containing a query string to the same uri without the query_string.
RewriteCond %{THE_REQUEST} ^GET\ /.*\;.*\ HTTP/
RewriteCond %{QUERY_STRING} !^$
RewriteRule .* http://www.askapache.com%{REQUEST_URI}? [R=301,L]
This .htaccess rewrite example invisibly rewrites requests for all Adobe pdf files to be handled by /cgi-bin/pdf-script.php
RewriteRule ^(.+)\.pdf$ /cgi-bin/pdf-script.php?file=$1.pdf [L,NC,QSA]
For sites using multiviews or with multiple language capabilities, it is nice to be able to send the correct language automatically based on the clients preferred language.
RewriteCond %{HTTP:Accept-Language} ^.*(de|es|fr|it|ja|ru|en).*$ [NC]
RewriteRule ^(.*)$ - [env=prefer-language:%1]
This allows access to all files by php fopen, but denies anyone else.
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^.+$ [NC]
RewriteRule .* - [F,L]
If you are looking for ways to block or deny specific requests/visitors, then you should definately read Blacklist with mod_rewrite. I give it a 10/10
This can be very handy if you want to serve media files or special downloads but only through a php proxy script.
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+)/.*\ HTTP [NC]
RewriteRule .* - [F,L]
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^askapache\.com$ [NC]
RewriteRule ^(.*)$ http://askapache.com/$1 [R=301,L]
Uses a RewriteCond Directive to check QUERY_STRING for passkey, if it doesn’t find it it redirects all requests for anything in the /logged-in/ directory to the /login.php script.
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} !passkey
RewriteRule ^/logged-in/(.*)$ /login.php [L]
If the QUERY_STRING has any value at all besides blank than the?at the end of /login.php? tells mod_rewrite to remove the QUERY_STRING from login.php and redirect.
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} .
RewriteRule ^login.php /login.php? [L]
An error message related to this isRequest exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.or you may seeRequest exceeded the limit,probable configuration error,Use 'LogLevel debug' to get a backtrace, orUse 'LimitInternalRecursion' to increase the limit if necessary
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule .* - [L]
RewriteRule ^(.*)\.php$ /$1.html [R=301,L]
Redirects all files that end in .html to be served from filename.php so it looks like all your pages are .html but really they are .php
RewriteRule ^(.*)\.html$ $1.php [R=301,L]
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
# If the hour is 16 (4 PM) Then deny all access
RewriteCond %{TIME_HOUR} ^16$
RewriteRule ^.*$ - [F,L]
Converts all underscores “_” in urls to hyphens “-” for SEO benefits… See the full article for more info.
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule !\.(html|php)$ - [S=4]
RewriteRule ^([^_]*)_([^_]*)_([^_]*)_([^_]*)_(.*)$ $1-$2-$3-$4-$5 [E=uscor:Yes]
RewriteRule ^([^_]*)_([^_]*)_([^_]*)_(.*)$ $1-$2-$3-$4 [E=uscor:Yes]
RewriteRule ^([^_]*)_([^_]*)_(.*)$ $1-$2-$3 [E=uscor:Yes]
RewriteRule ^([^_]*)_(.*)$ $1-$2 [E=uscor:Yes]
RewriteCond %{ENV:uscor} ^Yes$
RewriteRule (.*) http://d.com/$1 [R=301,L]
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\.[a-z-]+\.[a-z]{2,6} [NC]
RewriteCond %{HTTP_HOST} ([a-z-]+\.[a-z]{2,6})$ [NC]
RewriteRule ^/(.*)$ http://%1/$1 [R=301,L]
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} \.([a-z-]+\.[a-z]{2,6})$ [NC]
RewriteRule ^/(.*)$ http://%1/$1 [R=301,L]
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} \.([^\.]+\.[^\.0-9]+)$
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
Full article:Redirecting Wordpress Feeds to Feedburner
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/feed\.gif$
RewriteRule .* - [L]
RewriteCond %{HTTP_USER_AGENT} !^.*(FeedBurner|FeedValidator) [NC]
RewriteRule ^feed/?.*$ http://feeds.feedburner.com/apache/htaccess [L,R=302]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
Article: Request Methods
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_METHOD} !^(GET|PUT)
RewriteRule .* - [F]
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?askapache.com/.*$ [NC]
RewriteRule \.(gif|jpg|swf|flv|png)$ /feed/ [R=302,L]
RewriteEngine On
SetEnvIfNoCase X-Forwarded-For .+ proxy=yes
SetEnvIfNoCase X-moz prefetch no_access=yes
# block pre-fetch requests with X-moz headers
RewriteCond %{ENV:no_access} yes
RewriteRule .* - [F,L]
This module uses a rule-based rewriting engine (based on a regular-expression parser) to rewrite requested URLs on the fly. It supports an unlimited number of rules and an unlimited number of attached rule conditions for each rule, to provide a really flexible and powerful URL manipulation mechanism. The URL manipulations can depend on various tests, of server variables, environment variables, HTTP headers, or time stamps. Even external database lookups in various formats can be used to achieve highly granular URL matching.
This module operates on the full URLs (including the path-info part) both in per-server context (
httpd.conf) and per-directory context (.htaccess) and can generate query-string parts on result. The rewritten result can lead to internal sub-processing, external request redirection or even to an internal proxy throughput.Further details, discussion, and examples, are provided in the detailed mod_rewrite documentation.
If you aren’t already comfortable using mod_rewrite then I recommend this excellent mod_rewrite guide by one of my favorite mod_rewrite gurus that I’ve met.
« Search Engine Friendly Redirects | .htaccess Tutorial Index | » Speed up your site with Caching and cache-control
« Blocking Bad Bots and Scrapers with .htaccess
Undetectable Sniffing On Ethernet »
Tags: htaccess, htaccess rewrite, mod_rewrite, Redirecting URLS, rewrite, Rewrite Tricks, rewritecond, rewriterule
Please consider donating to support active development of the free software and articles here.![]()
The power of the Web is in its universality. Access by everyone regardless of disability is an essential aspect. Tim Berners-Lee
I have several domains point to the same htdocs directory.
i have some static content that resides under htdocs/domain.com/images/blah.jpg so how do i take a request that is images/blah.jpg and properly check against htdocs/domain.com/images/blah.jpg and if the file doesn’t exist then go to view.php?search=images/blah.jpg ?
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteCond %1/%{REQUEST_FILENAME} -f
RewriteCond %1/%{REQUEST_FILENAME} -d
RewriteRule index.php?=%{REQUEST_FILENAME} [L]
Awesome job, this was the page that pulled all the pieces together for me.
Thanks!
Richard
2nd Follow-up on REQUIRE NO SUBDOMAIN — the other (first) prototype above
Just a note on the other version above. It reads:
RewriteCond %{HTTP_HOST} \.([a-z-]+\.[a-z]{2,6})$ [NC]
RewriteRule ^/(.*)$ http://%1/$1 [R=301,L]
It may be worth noting that the domain name part of the filter is missing numbers. That is, the class “[a-z-]” means any lower case alphabetical character and the “-” dash symbol, but numbers can also be used in domains. I still do not see why the forward slash is placed preceding the $1 in the rewrite (see earlier comments on this). So I propose the following instead:
RewriteCond %{HTTP_HOST} \.([a-z0-9-]+\.[a-z]{2,6})$ [NC]
RewriteRule ^/(.*)$ http://%1$1 [R=301]
Follow up to previous post about REQUIRE NO SUBDOMAIN
I have tried the following bit of code and it seems to work in every conceivable case. I have a mixed SSL and non-SSL website with gates directing according back and forth accordingly. The Rewrite directive with the “http://...” doesnt cause problems, I think for the reasons I outlined in the previous post. Also, I run some servers on nonnormal ports for SSL (i.e., not 443) but this recipe also seems to work when explicitly detailing the port in the request (i.e., https://garbage-I-want-to-get-rid-of.myDomain.com:445/some/path ). I guess the reason is that HTTP_HOST includes the port number as part of the variable and I have NOT excluded numbers in the second negative class of the conditional (unlike in the original REQUIRE NO SUBDOMAIN above and so they do not get rewritten.
In any case, the code I am using (successfully… so far) is:
RewriteCond %{HTTP_HOST} \.([^.]+\.[^.]+)$
RewriteRule ^(.*)$ http://%1$1 [R=301]
Note also I have omitted the “L” tag — I have and you might have further Rewrites in he same directory…
Also note: per my previous note, I removed the backslash \ escapes from the character classes in the conditionals without problem, so I assume the original taken from here was not optimal. For comparison, the older version I am referring to reads:
RewriteCond %{HTTP_HOST} \.([^\.]+\.[^\.0-9]+)$
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
Wonderful work/tutorial! A real pleasure to see actually how apache operates!!
Question:
In the second example of No Subdomains it states:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} \.([^\.]+\.[^\.0-9]+)$
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
Why are the “.” in the classes escaped with \ ? Are not all meta characters automatically escaped in class ranges?
Why or how does the “/” work in the %1/$1? Does not the $1 already include the / ?
In the second class
the numbers must be there for the case where a port has been identified I assume (?), because an IP address would anyway show up with 2 or more “[^\.0-9].” But then, shouldn’t “:” also be included? Or did I miss something?
As an aside, I think this also works for cases where one is alternating between SSL and otherwise if (and only if) one has further rewrites to handle where the page should be encrypted. From the tutorial I read it would seem that when authentication is processed, the returned page will be passed once through to get the domain correct, but then on the second pass will not be rewritten (as it not longer meets the conditions) and so be forced to SLL (by whatever other rewrites or redirects are present).
I want to add the ability to put a hyphen in the subdomain. Can I do this also with .htaccess rewrite? If so how do I code this?
Hi,
Awesome information Please provide me the solution for the following.
I have used the following redirection code in my .htaccess file which used to work fine in server where I hosted early.
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/(.*).html
RewriteRule ^(.*).html /math-tutorial/tutor.php?name=$1 [L]
The Rewrite condition work perfectly, but not the rewrite rule.
Thanks
I’ve been trying to change php extensions to html for the last week and they simply will not abide by the rule
RewriteBase /
RewriteRule ^(.*)-p-(.*).html$ .php?city=$2&%{QUERY_STRING}
It’s dring me crazy :(
Any help would be cool
Super htaccess article.
It was a good help to me.
Thanks.
Great stuff here! However, I don’t completely understand the Prevent Hotlinks example code you’ve given. In the code you list your domain name — should that be MY domain name when I’m implementing? What’s up with the /feed/ element?
I noticed that the version at this site replaced /feed/ with /feed.gif — I don’t get it…
That site also added the line
Options +FollowSymLinks
at the beginning of their Prevent Hotlinks example. Is that correct/needed?
Thanks!
I want when a user comes to site.com, it automatically shows the content site.com/username and all the requests like site.com/profile.php?id=xxx
Can anybody write that script for me, or guide me to the nearest search engine, because I can’t find any search engines, and I don’t know how to use google.
Great tips. All very usefull, and I needed them all!
Thanks!
Excellent article, BTW. So here’s my issue. I am using htaccess to do mod_rewriting for friendly URLs (in MODx CMS), but I also need to redirect all the old pages from the old site (.php files). I’ve been trying to use Redirect 301 directives but they fail.
So I did some searching and came across a possible solution, but I have yet to make it work, hopefully you can help:
I am trying to get http://example.com/page.php?jan=$1 to redirect to a url without those variables visible.
Here’s what I have:
Options +FollowSymlinks RewriteEngine On RewriteBase / # Redirects RewriteRule ^page.php?jan=$1 /text-to-article [R=301,L]
I have a list of about 100 files, not all have variables, but all are php files.
Thanks :)
How to simply rewrite all my .php extensions to .html. This is my .htaccess file but it is not working properly. My homepage doesn’t display anymore!!
Options +FollowSymLinks RewriteEngine On RewriteRule ^(.*)\.php$ /$1.html [R=301,L]
Nice post!
But It didn’t help me with my issue…
I am currently hosting at example.domain.com and have purchased example.com
When I use mask URL for my domain forwarding, I always see example.com in the browser
I want that when the ‘my-post’ link is clicked, the URL should show as example.com/my-post (since internal request generated is example.domain.com/my-post
Can someone help me please
I have a WordPress site and am using:
RedirectMatch 302 /download/example(.*) http://example.com/id=1234&profile=54321$1
for redirects in my .htaccess file to my affiliate links but everything seems to go horribly wrong when using ampersands in my redirected urls and they are required in many instances.
Anyone have any ideas on how to fix this?
You know, it’s more realistic to be forcing users NOT use www instead of requiring www. The subdomain www is deprecated nowadays, since modern systems know what service you are requesting without needing a separate zone for each.
Just thought this was worth mention.
Hello There.. I dont know much about .htaccess
I have a small issue, let me explain.. I have Joomla installed in the /Joomla directory..
eg: site .com/Joomla
I want when a user comes to site .com, it automatically shows the content of site .com/Joomla
and all the requests like site .com/index.php?com=xxx etc to site .com/Joomla/index.php?com=xxx
means i want to remove the use of ‘Joomla’ string, without physically delete it
Can anybody write that script for me, or guide me
Thanks
your css has put a strike or del through everything, making it a little hard to read. Might want to fix that.
Thanks!
hi all
how to secure specified folder using in apache in htacces file..
These redirects work in my “httpd.conf” but not in my .htaccess file.
My .htaccess is working because other directives work in there such as ErrorDocument.
My setup is Apache 2.2, Tomcat 6.0, Windows.
Any ideas?
nice tips, is missing a rule to block PHP injection attempts:
RewriteCond %{QUERY_STRING} ^(.*)=http: [NC]
RewriteRule ^(.*)$ - [F,L]
hello everyone,
I am new in php developing, i am do code for mod_rewrite for my site it is run well but problem is when i rewrite my URL page give right output but my css and images not appeared please sugest me for this prob
thanks in advance… santy.
I think it can be great, adding more
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
.htaccess usage samples with file handlers.
Please add some tutorials and .htaccess code samples about it.
Thanks for the collection. It extends my understanding to the capability of a htaccess file : )
Thanks, very useful .htaccess examples and well layed out.
very nice .htaccess tutorial!
now i can put hotlinking protection :)
greetings!
Hi,
I just want to ask one question, for example: if I have website with URL address http://www.example.com/index.php?option=com_user
But I just want to display URL like “http://www.example.com/“.
What should I do?
Thanks in advance
Hey thanks for this tutorial – very awesome, but i still have a lot to learn about htaccess – mabe you can help me. i believe my request is simple.
i want to take any request for http://www.example.com/img###
where ### is an integer from 1 to 99999
and redirect the user to
http://www.example.com/php/image_db/file.php?id=###
where ### is said number.
it seems easy enough? right?
thanks for the help in advance!
I like to generate a random directory name in the URL with .htaccess, is it possible?
www.site.com.htaccess redirects towww.site.com/.sdf4p/so, I want to generate this “.sdf4p” string randomly for each request (directory names aren’t generated in advanced, so I need to pick randomly. I just want to create that string randomly). but how?
thanks for your help.
Hi,
I have been stuck with this one for a pretty long time. I m zero when it comes to htacees. hence i need a little help. I have subdomain under my site mentioned above /iphone, working fine, but the link below to visit next pages does not work cuz the url is wrong. its supposed to be /iphone/page/pagenumber where as it shows up /page/pagenumber. my rewrite rule is
RewriteRule ^iphone/page/([0-9999]+)/?$ /index.php?postpage=$1 [L,QSA]
Can someone help me with this?
Brilliant – just what I needed! Thanks for putting this htaccess rewrite guide together.
Hi i’ve tried your methods for activating url rewriting on my website but nothing happens. I test locally on my laptop running Kubuntu Linux 7.10 and nada. I desire to use rewrite for three specific php files..
Please i really need the help
YES! YES! YES! rewrite .htaccess, hack htacess to hide index.php, static ip address,htaccess auto_prepend_file,htaccess rewritecond .php,php synchronize files,rewrite dynamic urls to flat
zomg, this is one of the most useful pages on the internets!
@These are awesome..
I wonder if you can help with one rule? I want to direct:
domain/archive/some-text.php?123 to: domain/archive.php?123 I have tried multiple variations but can’t figure that out. Any ideas? I would sure appreciate it!!
If you have tried the right variations you may not have Apache Rewrite enabled…
But if you do… you could try something like this…
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule (.*) http://www.weathat.com/$1 [R=301,L]
## Activate the mod_rewrite Engine
## Support for LookBack + 'ForceType'
RewriteRule ^(index|shop)/(.*)$ index.php/$2 [L,NC]
## Support for Apache RewriteRule
RewriteRule cat_([0-9]+)(\.[a-z]{3,4})?(\?.*)?$ index.php?_a=viewCat&catId=$1&$3 [L,NC]
RewriteRule prod_([0-9]+)(\.[a-z]{3,4})?(\?.*)?$ index.php?_a=viewProd&productId=$1&%3 [L,NC]
RewriteRule info_([0-9]+)(\.[a-z]{3,4})?(\?.*)?$ index.php?_a=viewDoc&docId=$1&$3 [L,NC]
RewriteRule tell_([0-9]+)(\.[a-z]{3,4})?(\?.*)?$ index.php?_a=tellafriend&productId=$1&$3 [L,NC]
RewriteRule _(saleItems)(\.[a-z]+)?(\?.*)?$ index.php?_a=viewCat&catId=$1&$3 [L,NC]
— I wouldn’t recommend leaving the “?” in the display as this indicates a dynamic page and some search engines cannot index them.
Good Luck.
These are awesome.. I wonder if you can help with one rule? I want to direct:
domain/archive/some-text.php?123
to:
domain/archive.php?123
I have tried multiple variations but can’t figure that out. Any ideas? I would sure appreciate it!!
I use the following code on my site, however I would like the /support/ directory to be skipped, so the rewrites do not apply to it. I did try to place a .htaccess with RewriteEngine Off, in the support directory, however, that didn’t do the trick.
Any suggestions?
Options +FollowSymlinks
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
# Rewrite current-style URLs of the form 'index.php?q=x'.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.cgi?q=$1 [L,QSA]
Hi,
I want to redirect all requests for flv files to another website dir.
I have “www.site.com/flvideo/” and I want to redirect to “www.anotherdomain.com/flvideo/”
What rewrite rule should I write in order to achieve this ?
Thanks
wow , fantatist tips !!
i ll try to do it for my website:
I have only a question, is important for SEO the files end with .html ? like: web/page1.html or the simple can have an address like: web/page
thanks!
you can look my modrewrite with basic things
RewriteCond %{HTTP_HOST} !^domain.com [NC]
RewriteCond %{HTTP_HOST} ^(www.)?([^.]+).domain.com [NC]
RewriteRule ^$ /fake_subdomain.php?page=tag&tag=%2 [L]
making sub domains can bee added :)
good article thnx friend… Mod_rewrite favorite…
Just a short note to thank you for this page, it has helped me countless times, I come here every time I need to modify my htaccess file so, many thanks for your help, I love the caching article too :)
mark
Hey, I’ve been reading around your entries. Very helpful. :)
I’m actually in a bind here, and maybe you could help? I’m noticing that .cur files that are missing are not recorded in my error log. I’m also unable to redirect or even just rewrite the cursor files that are missing to ones that exist. I’m using 403 404 500 and 301 back and forth to see if anything works, but so far, nothing. Help? :)
I was working on some .htaccess file and moved all the NON-www to www. but in the process this also moved the subdomains like shop.weathat_com to www.weathat_com/shop/ Although this works and creates working pages, I would like to keep the non to www. redirect but also keep the subdomain non redirect. It isn’t letting me do this so is there another way?
Also I would like to make www.shop.weathat_com revert to shop.weathat_com
My htaccess file looks like this.
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule (.*) http://www.weathat_com/$1 [R=301,L]
RewriteEngine On
RewriteBase /
++++ some other stuff for removing the dynamic URLs
After all the searching on the Net I couldn’t find the answer.
And one more question? Is my Ranking Better for having the subdomain transfer to a directory folder?
Thanks, Mike
Great post! I’ve done a little work with .htaccess but I find the syntax a little confusing. Here’s what I would like to do… I would like to create a ‘mobile’ theme for my blog and allow people to go to it simply by the subdomain.
In other words, if the subdomain is www or no www, any direction to the themes would stay as they are:
www.site.com/wp-content/themes/
However, if the subdomain is mobile:
mobile.site.com
Any references to the theme would be redirected to:
www.site.com/wp-content/themes/mobile
Is that possible?
Thanks!
Doug
i especially liked “some one is reading”. how u implemented that?
wow… great tutorial :)
thanks a lot :)
Cool, we need this on TekTag.com. We’ve bookmarked it for ourselves, but I think the general community would like it.
It's very simple - you read the protocol and write the code. -Bill Joy
HTML | DCMI | GRDDL | XOXO | XDMP | XFN | DOM | XML | XHTML 1.1 Strict | CSS 2.1 | W3C | TLDP | WAI | DISA | ICSI | GIAC | SANS RR | GHOST | DEFCON | NIST | DHS CYBER | NIST | .:: Phrack Magazine ::.
↑ TOPExcept where otherwise noted, content on this site is licensed under a Creative Commons Attribution 3.0 License, just credit with a link.
This site is not supported or endorsed by The Apache Software Foundation (ASF). All software and documentation produced by The ASF is licensed. "Apache" is a trademark of The ASF. HTTPD based on NCSA HTTPd
With all the mod_rewrite articles out there that show you how to redirect a request, none of them show you how to keep the url in the address bar the same?
For example, you say you can redirect:
/somepage-1234.html
to the page:
/?somepage=1234 [R=301]
But when you do that, the user is taken to that page, and it is shown in the address bar as the dynamic page. So how to you keep the original url in the address bar?