apache Apache mod-rewrite and htaccess related Articles htaccess mod-rewrite

Commonly used regular expression patterns in apache RewriteRule

Regex in RewriteRule
RewriteRule directive uses a Regular expression based pattern to match against URL path. In this post we will cover some basic and commonly used patterns that are most often used in RewriteRule.

RewriteRule basic regex

  • (.*) Catch-all and save (zero or more characters)
  • (.+) Catch-all and save (one or more characters)
  • ([a-zA-Z0-9]+) Catch-all alpha numbric Chars (A to Z , a-z and 0-9)
  • ([0-9]+) Catch-all numbric Chars in URI ( 0-9)
  • ([a-z]+) Catch-all lower case URI chars (a to z)

(.*) matches all characters in URI and saves the value in $1 variable which can be used in rule’s substitution string.

RewriteRule (.*) /file.php/$1 [R]

The rewrite rule above will redirect any URI to /file.php/anyURi . The pattern (.*) matches all URL paths including / (hompage). The $n variable holds whatever (.*) captures.

(.+) matches one or more characters in an URI string and saves the matched value in $1 variable.

RewriteRule (.+) /file.php/$1 [R]

The rule above will redirect /anyURI to /file.php/anyURI . The difference between + and * in the pattern is that + means to match one or more time . The minimum required character in URI is one while the * matches zero or more time. The pattern (.+) will not match your hompage “/” as the single “/” is treated as no char in RewriteRule.

([a-zA-Z0-9]+) matches alphabetical characters in URI. Only the characters you put inside [] are matched. A-Z matches UPPER CASE characters ranging from A-Z .

RewriteRule ([a-zA-Z0-9]+) /file.php/$1 [R]

Our RewriteRule above will match all uri of the following formats /thisuri , /ThisURI123 etc..

([0-9]+) matches a numbric URI string ie “/123” .

RewriteRule ^([0-9]+)$ /file.php/$1 [R]

The rule above will redirect to . The ^ indicates start of the URI string and $ indicates end of the string . If the ^ and $ are removed in the rule above then the rule will also redirect but the pattern will only capture numberic part of the uri “123”

^([a-z]+)$ matches lower case alphabetical URI characters ie. ””

RewriteRule ^([a-z]+)$ /file.php/$1 [R]

I hope it was helpful. Thanks for reading.

apache htaccess mod-rewrite

How to redirect non-logged in users using RewriteRule in htaccess

Redirect based on cookie value htaccess

Redirect non-logged in users using htaccess

With apache mod-rewrite it is quite possible to manipulate http cookies. The cookie you set using php or RewriteRule can easily be accessed using RewriteCond directive.
If you need to redirect your non-logged in users of your website to a diffrent page using RewriteRule you need to check the COOKIES in RewriteCond directive .
You can use %{HTTP_COOKIE} variable which is a pre defined mod-rewrite variable to check if the user visiting your site has cookies set.
Assuming the following user cookie is set user=loggedin
You can simply use a RewriteRule to redirect your non-logged in users to a diffrent page based on if the cookie exists.

RewriteEngine on
RewriteCond %{HTTP_COOKIE} !^user=loggedin$ [NC]
RewriteRule ^ /page2.php [L,R]

The rewrite rule above will redirect user to /page2.php if the cookie user=loggedin doesnt exist or isnt set. The rule also redirects files like css , js and other website resources. You can simply add other conditions to exclude your existent files so that it can only redirect the user request. The following rule should work in that case :

RewriteEngine on
#exclude files
RewriteCond %{REQUEST_FILENAME} !-f
#exclude dirs
RewriteCond %{REQUEST_FILENAME} !-d

RewriteCond %{HTTP_COOKIE} !^user=loggedin$ [NC]
RewriteRule ^ /page2.php [L,R]

apache htaccess mod-rewrite

How to use mod rewrite %{THE_REQUEST} variable in htaccess?

How to use THE_REQUEST

Many users who use htaccess often get confused by mod-rewrite %{THE_REQUEST} variable. The questions what is it and how do we use it appear on their mind. In this post I will explain what %{THE_REQUEST} actually is and how we can use it in rewriteRule.

What is %{THE_REQUEST} in mod rewrite?

%{THE_REQUEST} is a mod rewrite per defined variable like other variable ie %{HTTP_HOST} . To understand what URI string the_request variable actually contains you can write a rule to print it.
THE_REQUEST variable contains the full URI string including Request method and Server protocol. The following is the example of THE_REQUEST string . When you type /file.php in your browser , your browser sends the following request to server:

GET /file.php HTTP/1.1

  • GET is the request method
  • /file.php is the file you requested.
  • HTTP/1.1 is the protocol version of your apache server.

We use %{THE_REQUEST} in RewriteCond to conditionally rewrite urls and avoid infinite loop error as this variable works as an anti loop protection for rewriteRules.

RewriteEngine On
RewriteCond %{THE_REQUEST} GETs/file.phpsHTTP1.1 [NC]
RewriteRule (.*) /file [R]

In the example above we match against %{THE_REQUEST} using regex. If the regex pattern matches then the rule is triggered. The rule will redirect /file.php to /file. You can also use a simple regex pattern that only matches the file name

RewriteEngine On
RewriteCond %{THE_REQUEST} file.php [NC]
RewriteRule (.*) /file [R]

THE_REQUEST variable is often used with rules that remove file extensions. When two rules (Rule with R flag and Rule with L) rewrite the same file name THE_THE_REQUEST should be used at the top of External rewrite rule (Rule with R flag) to avoid the loop error.

Apache mod-rewrite and htaccess related Articles htaccess mod-rewrite

Remove multiple file extensions using RewriteRule in htaccess.

Remove html PHP extension using htaccess

How to remove multiple file extensions using RewriteRule in htaccess ?

.htaccess is a directory level configuration file used on apache server. Many users who don’t have access to their main server.config file use htaccess to rewrite URLs and configure other custom server settings. Htaccess is often used by Apache users to shorten URLs when they want to turn a long and non-memorable URL into short and memorable one. One of the most used rewriteRule on htaccess is “File extension removal” rule. Users find it easier then server.config to RewriteRule through htaccess. In this post I will show you how you can remove any file extension using htaccess.

What you will need:

  • Apache server
  • Mod-rewrite
  • .htaccess support

Apache server

You must have an apache server to use RewriteRules.


Mod-rewrite is a rewrite module provided by apache. You must have this module enabled on your server in order to use RewriteRules directive. Some hosting service providers have enabled it by default but in case its not enabled ,you can enable it by adding one mazic line AllowOverride All in your server.config file. If you don’t have access to this file then ask your hosting service to enable it for you.


.htaccess is where you will write rule code. htaccess is a dot perfix file. If your hosting service hasn’t enabled it then ask them to enable it.

Remove file extension using RewriteRule

With a RewriteRule directive, you can remove the traling .php from your php files. For example You will only type /filename instead of /filename.php . Filenames with extension do not cause any SEO issues but if you remove the extension then appearance of URL becomes awasome. The following is the rule to remove .php extension from urls. You can edit it to remove other extensions accordingly by just replacing .php with your file extension :

RewriteEngine on
RewriteRule %{THE_REQUEST} /(.*).php [NC]
RewriteRule (.*) /%1 [L,R]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule (.*)/?$ /$1.php [L]

The rewrite rule above would redirect any php file url ie (foo.php) to remove the extension. The first set of rule redirects /file.php to /file and the second one then internally maps /file to its original location /file.php .

Remove multiple file extensions using RewriteRule in htaccess

It is possible to remove multiple file extensions using two rules. You can capture file extensions using regex in RewriteCond and then rewrite the request accordingly.

RewriteEngine on
RewriteCond %{THE_REQUEST} /([^.]+).(php|html|css) [NC]
RewriteRule ^ /%1 [L,R]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule (.*)/?$ /$1.php [NC,L]

The simple approach works for any file extension you want to remove.

apache htaccess mod-rewrite

Diffrence between URL rewriting and URL redirection htaccess topic

URL rewriting and URL redirection are two different terms used to map a URL from one location to the other. These two terms often confuse new users especially when they refer to URL related queries. Some users even intermix the URL rewriting logic with URL redirection like they are talking about a particular thing with two different languages. I often see such questions on StackOverflow and encourage posters to fix it.

In this post I will give you a clear overview of what these two terms actually mean and how we use them with URLs.

URL redirection

URL redirection is when an URL redirects from one location to the other and the appriance of URL changes in browser address bar from old to new (from the typed URL to the new location). URL redirction happens client side . Server gives a command to your web browser to change the URL to a new location. Lets understand with a real world example : if you click on this link my server will send a redirect command to your browser to go from this page to

Notice how the URL changes in your browser address bar to This redirection is also called external redirection or transpirant redirection as its visible to your web browser and your browser knows whats happening on the screen. On apache server you can create a Redirect either by using a file based method in html, PHP or using Redirect commands in htaccess or server.config file. Apache server provides multiple methods to redirect URLs by htaccess. There are 2 diffrent modules that you can use for URL redirection on apache Mod-alias and mod-rewrite both modules support htaccess and server.config context.

4 ways to redirect URLs on apache server

Given bellow are the common methods to redirect URLs from a website.

  1. HTML:
    HTML anchor tag (a) is used to redirect the currunt page URL to a specific location
    <a href=””&#62redirect to”</a>

  2. PHP:
    Redirecting the current page to

  3. Redirecting a specific path to using Redirect directive in htaccess:
    Redirect /path

  4. Redirecting a specific path to using RewriteRule in htaccess:

    RewriteEngine on
    RewriteRule ^thispath [R]

URL rewriting

URL rewriting is way of rewriting urls. URL rewriting is When a URL path internally maps to another path on server. By “internally” I mean an “Invisible URL redirection” . You and your browser can’t see how the url changes from Old to new as it starts and ends behind the screen and your browser stays on the same URL. URL rewriting is server side only as it happens on a webserver without informing the client of the redirection. You get the web page from new location on the same (typed) url as it doesn’t change from old to the new one.
URL rewriting is also called internal URL or invisible url redirection as its invisible to a web browser only the webserver executes this redirection and sends the contents of the new page to browser. For example the following url can be rewritten to by using a RewriteRule directive on apache server. And then instead of typing /file.php you can simply type the new url /file your server will internally redirect/rewrite it to /file.php serving you the contents of /file.php on the /file URI.

Rewriting URLs on apache server

Apache server provides mod-rewrite module for rewriting URLs. In order to use this module you must first enable it on your server if it isnt already enabled.
There are hundreds of URLs rewriting basic examples on Apache guide if you are new you can read their complete guide to understand how it works . To rewrite URLs on apache server, you can either use your config file or your htaccess to write rules.
URL rewriting is done by using RewriteRule directive of mod-rewrite module. The following is a basic example of how we use RewriteRule in an htaccess file. The rule rewrites /a.php to /b.php .

RewriteEngine on
RewriteRule ^a.php$ /b.php [L]

apache htaccess mod-rewrite

How to set cookies using RewriteRule in htaccess file?

How to set cookies in htaccess

In this post I will show you how we can set an http cookie using a RewriteRule directive in an htaccess or server.config file.
I saw many unanswered and some wrong answered posts on StackOverflow and on other sites so I thought It would be worth writing a post here that can help peope looking for help regarding Htaccess and mod_rewrite cookies.

Setting cookies using mod_rewrite

With RewriteRule directive you can set http cookies the same way you use the directive for rewriting URLs. Cookies are set using [CO] Cookie flag of apache mod-rewrite. The cookies you set via RewriteRule can also be accessed by client or server scripting languages like PHP and JS.

Mod rewrite cookies are mainy used for rewriting requests based on http cookie header.
You often set a mod rewrite cookie to rewrite/direct URLs if a specific cookie exists or based on cookie value .

Let’s start with a basic example first:

RewriteEngine On
RewriteRule (.*) - [CO=user:john]

The rewrite rule above will set cookie named user and as you can see we manually assigned value john to it.
Explanation :

  • The first line “RewriteEngine on” tells server to turn on the engine for rewriting URLs. This setting is disabled by default so you must use this line ones at the top of RewriteRules in htaccess or server.config files.
  • The second line is that does the Rewrite mazic and sets the cookie whenever you request an URI from server.
    RewriteRule (.*) – [CO=user:john]” matches any incoming URIs as the pattern (.*) means to match anything. The hyphen in the Rule’s destination above lets the URI pass through unchanged meaning that if the request is for /file.php only the CO flag will be applied to the URL and there will not be any change in the URL. In most cases when setting cookies by RewriteRule you use as the destination path because we don’t want to rewrite the urls we just want to set a cookie for URLs.
    [CO=user:john]” sets user cookie with value john. You can also use a dynamic value using regex match “$1” or “%1” .

Setting cookies for specific URIs with mod_rewrite

In the basic example above we learned how to set cookies when any URL passes through RewriteRule. You can also set cookies for a specific URI. For example to set cookies only for a single path or file ie /this-file.php you can restrict the pattern of RewriteRule to match only this URI. You just need to write a regular expression pattern to match that particular path.

RewriteEngine On
RewriteRule ^this-file.php$ - [CO=user:john]

This will set the cookie only when you request /this-file.php . This rule example might fail on server.config, add a leading slash in the pattern ie: ^/this-file.php$ to use this in a server.config file.

We use RewriteCond directive to check whether a cookie is set or notset and to test the value of a cookie that is already set. We can also check what value the cookie holds. The following is a basic example of checking whether a cookie is set :

RewriteCond %{HTTP_COOKIE} !^$

In the example above we want to make sure our cookie is set or not empty (!^$) . You can use a RewriteRule bellow this condition so it executes if the condition is met.

In the example bellow, we will redirect /this-file.php to root / if our user cookie is not set.

RewriteEngine on
RewriteCond %{HTTP_COOKIE} !user
RewriteRule ^this-file.php$ / [R,L]

RewriteEngine on
RewriteCond %{HTTP_COOKIE} ^user=john
RewriteRule ^this-file.php$ / [R,L]

The rule above will redirect /this-file.php to / if the cookie user and value john is set.

You can set a specific cookies if it doesn’t exist using the following RewriteRule:

RewriteEngine on
RewriteCond %{HTTP_COOKIE} !^user=john
RewriteRule .* - [CO=user:john,L]

In the example above we first check the HTTP_COOKIE header to ensure that the cookie “user=john” is notset and then we set it via RewriteRule.

By default, mod-rewrite cookies are set for all domains that point to the same document root. You can add an optional perameter domain to the CO flag. To set cookies only for a specific host you will use something like the following:

RewriteEngine on
RewriteCond %{HTTP_COOKIE} !^user=john
RewriteRule ^this-file.php$ - [,L]

By default mod-rewrite cookies are set for current session only which means when the browser window is closed the cookies also get destroyed. You can add a lifetime perameter in minutes to CO flag to customise cookies validity.

RewriteEngine on
RewriteRule ^this-file.php$ - [,L]

In the example above the user cookie is available only on host and it expires after 10 minutes.

Cookies for specific path only

You can make the cookies available for a specific path only. By default mod-rewrite cookies are set for / which means the entire site. To set a specific path you may use :

RewriteEngine on
RewriteRule ^this-file.php$ - [,L]

Setting cookies expire time

You can set how long an http cookie will survive, by default mod-rewrite cookies are set for current browser session only and deleted when we close the browser window. You can add a time perameter to CO flag to extend the cookie validity . Time value is set in minutes.

RewriteEngine on
RewriteRule ^this-file.php$ - [,L]

This will set user cookie on host with a validity of 10 minutes.

Apache mod-rewrite and htaccess related Articles htaccess moder rewrite rules

5 awesome htaccess copy and paste Rewrite rules with explanations

htaccess RewriteRules

I often see people struggling with their mod-rewrite code and when they think they can’t fix the issue themselves, they either go to stackoverflow or keep scrolling the search results and hopefully ,perhaps get the solution there.

URL rewriting is not as complicated as new users find it. Like other languages, URL rewriting is a mazic of syntex. If you are learning from the scratch then learning its basic syntex first can help you better understand it and speed up your learning skill.

There are alot of learning resources on the Internet including the official mod-rewrite guide where you can start.

In this post, I am going to share 5 apache RewriteRule scripts that you can easily copy and paste to your server.config or htaccess
file to use them.

#1) Rewriting a long url to make it short and search engine friendly

With apache mod-rewrite, you can turn a longer looking URL into short one.
Let’s assume you have long URL with query variables which looks something like the following:

The one main problem with the URL above is that it is longer, not memorable and non-SEF . Search engines often ignore such URLs due to the duplicate URL issues.

To make the above URL short and SEF , you can use RewriteRule in your server.config or htaccess file.
With a RewriteRule you can turn the URL into the following format:

The URL looks awasome now. Doesn’t it?

RewriteRule script :
RewriteRule ^users/(.+)$ /users.php?user=$1 [L]

You can simply copy and paste the rule above to your htaccess or server.config file and put it bellow “RewriteEngine On” .

#2 Setting an environment variable using RewriteRule

You can set a URI based environment variable on your server using RewriteRule directive. Settings the variable via RewriteRule is easier then setting it in php. You can set an environment variable for specific URIs when these URIs pass through the RewriteRule.
The following RewriteRule code example sets an environment variable named foo and value bar for file.php meaning that when you request the /file.php the rule will automatically set the variable. You can copy the code from textarea bellow and put it in your htaccess file.

RewriteRule script :
RewriteRule ^file.php$ - [E=foo:bar]

#3) Access files without extensions

A simple one liner code to ignore file extensions on Apache server. If you want to access your files without typing extensions at the end, for example to
access file.html as file you can use the following line in your htaccess file :

Options +Multiviews

#4) non-www to www URL redirection

RewriteRules can be used to redirect a non-www (naked domain) to its www version. To redirect your non-www URLs to www , you can use the rule bellow:
RewriteEngine on
RewriteCond %{HTTP_HOST} !www. [NC]
RewriteRule (.*){REQUEST_URI} [R=301,L]

We use RewriteCond (condition) directive to test the host header string. If the test string %{HTTP_HOST} matches the pattern !^www then the rule is applied.. In simple words, if you type into your browser the rule will redirect it to .

#5) Custom 404 rule

With mod rewrite you can create a custom 404 rule for your website. You can redirect your visitors to a specific page on your site when they request a broken or not-found link.

The following RewriteRule script rewrites 404 requests to /file.php on your server. If you are using wordpress, add this before the WordPress default rule .

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*){REQUEST_URI} [R=301,L]

apache Seo

Should you htaccess or server.config file on apache server?

htaccess vs server.config . Which one should be used

Should you use htaccess or server.config file?

This is a common question among many apache mod-rewrite users especially among newbies as they are curious about it.
If you search this topic on google you will get hundreds of top results where experts advice you not to use htaccess.
One true answer to the question can be found on official apache mod-rewrite manual .

Screenshot from the official apache mod-rewrite manual:

htaccess vs server.config file apache

What is a server.config file?

It is a server level config file located in your httpd server root. You can put directives in this file to customize the behaviour of your server.

What is an htaccess file?

htaccess is a directory leve config file located in your document root.
By directory level I mean to say that you can use it in your main directory if you want the htaccess to effect the folder and its subfolders or you can also use it in a particular folder/subfolder so that it can affect the folder accordingly.

Not all hosting providers allow you to access server.config

Some paid or free webhosting providers do not allow you to edit server.config on their server that means that you only have access to a dynamic configuration file called .htaccess.
htaccess file can be placed anywhere in any directory .
Even wordpress installation contains an htaccess file to create short and friendly URLs.
But the question “Should I use htaccess or server.config file ” still keeps popping up in our mind and everyone seems to be curious to know it.

server.config or htaccess?

If you do not have access to the main config file on your server then You can use htaccess. There is nothing wrong with using an htaccess file. You won’t lose your seo rank. But there are some performance issues that can effect your site.
Apache mod rewrite documentation says that “htaccess file slows down the performance of a webserver” . Yes it does..but very little 0.5 or 1%. You can’t even notice how much your server performance and page load speed is affected.
So you don’t have be worried about it.
The difference between a server.config and an htaccess file is that you a server.config file supports all directives while an htaccess doesn’t like RewriteMap and there are some other useful directives that you cant use in an htaccess file.

Another big diffrence between these contexts is how a web server reads/executives these files. A server.config file is read by server only once. A htaccess file is read on each request. When you request sa file or directory from webserver , your webserver first reads the htaccess to serve you the file dir according to commands you put in htaccess. Server.config file on the on other is read only onec you update it.

To better understand how an htaccess file can slow down your webserver, consider the following example :

Say you an htaccess file in your directory to rewrite “/file.php” to “/file2.php” .

You type “/file.php” in your browser address bar.

You webserver receive the request “/file.php” .
In order to serve you the “/file2.php” your server reads your htaccess two times.
1) Your server reads your htaccess contents and rewrites “/file.php” to “/file2.php” .
2) Your server again reads your htaccess file to serve you the destination file “/file2.php” .
As you can see your webserver read your htaccess two times to serve a simple request. Then obviously your page load speed will degrees by 1 or 2% .

Apache mod-rewrite and htaccess related Articles

Most commonly used flags in RewriteRule | mod_rewrite flags

Flags are optional in mod_rewrite. They are used to change behaviour of RewriteRule directive. A RewriteRule can have at least one or multiple flags separated by a comma , character.
In RewriteRule flags are used inside sequere brackets [] .
The basic use of flags in RewriteRule is to instruct the engine how the rule should handle an http request. For example a rule with NC flag tells the engine to ignore URI character case so both Uppercase and Lowercase URIs are accepted by RewriteRule instead of just accepting lowercase URI which is the default behaviour.

This article covers all the most commonly used flags in RewriteRule with code examples and explainations on how they work.

Table of contents (Most used flags in RewriteRule)

[L] flag in RewriteRule

L stands for Last . We use L flag in RewriteRule to tell server that the rule is last. L flag gives instruction to server not to execute other rules if the specific one matches.

Forexample : If you have the following two rules in .htaccess file :

RewriteRule ^this /thispath
RewriteRule ^this /secondpath

As you can see the flag is ommited in rules above , so a request for /this will serve you the secondpath instead of the first rule’s destination path.
L flag is especially desigined to solve this type of rule’s confliction.

[NC] flag in RewriteRule

NC stands for NoCase . As the name states, this flag is used to match an URI in a case-insenstive manner meaning that your URI can contain both uppercase and lowercase URI characters.
The following is an example of NC flag in a RewriteRule :

RewriteRule ^hello$ /file.php [NC]

As you can we used NC in the rule above. With NC the Rule above will accept both URIs /hello and /HeLLo as the Case is ignored by NC flag.

[R] flag in RewriteRule

R stands for
Redirect . We use R flag in RewriteRule to redirect an URI from one location to the other. By default R redirects an URI using 302 redirect status which is temporary Redirect. You can manully append Redirect status code to R flag to change the redirect status ie: R=301 , R=403 etc.

See the rule example bellow to better understand how it works:

RewriteRule ^thisPath$ /thatPath [R=301]

The rewriteRule above will redirect /thisPath to /thatPath using the HTTP redirect status 301 changing the browser URL from old to new.

[QSA] flag in RewriteRule

QSA stands for
QueryStringAppend .
We use QSA in RewriteRule directive to combine new and old querystrings for example /this?q=bar to /that?query1=foo . QSA flag appends the old querystring to new target path like so /that?query=foo&q=bar.
You must use QSA in a RewriteRule when the target path of your rewriteRule already contains a querystring and you want to pass additional query perameters via your new URL to the old one.
The Rule example bellow will help you better understand the importance of QSA :

RewriteRule ^this.php$ /that.php?page=2 [QSA]

The rule above does two things, it rewrites /this.php to /that.php?page=2 and it will also pass additional query strings from your new URL path to the target path

forexample: /this.php?lang=en will also successfully map to /that.php?page=2&lang=en.

But if you remove the QSA then you wont get the same behaviour. Without QSA flag the additional query perameters you pass will get descarded.

[NE] flag in RewriteRule

NE | NoEscape flag tells apache not to convert special URI chracters like # , ? .. to their hex code. On apache server by default theses characters get changed ie # becomes %23 which can cause a not found url error on your server. See the example bellow we are using to redirect to a fregment path.

RewriteRule ^this$ /that#a [R,NE]

With NE flag the rule will redirect a request for /this$ to /that#a . If the NE is ommited then the URL you will land on would look something like /that%23a which is an invalid path.

[P] proxy flag in RewriteRule

P stands for Proxy . This flag is use in RewriteRule to proxy requests between two domains or two two different http hosts.
With P flag it is possible to rewrite your domain name to another domain without changing the URL in browser address bar.
To use P flag , first you must enable Proxy module on your Apache web server otherwise you will get a 500 “internal server error” .
The following is an example of P flag in a RewriteRule .

RewriteEngine on
RewriteRule (.*) [P]

This will internally map all requests from your domain to domain.

For example , a request for* will get served from without the URL change.