What is the difference between %1
and $1
in .htaccess?
For example,
# to remove www RewriteCond %{HTTP_HOST} ^(\w+)\.mydomain\.com [NC] RewriteRule .* http://mydomain.com/%1 [R=301,L] # versus # RewriteRule .* http://mydomain.com/$1 [R=301,L]
I have been using Dave Child's .htaccess cheat sheet and Jackol's .htaccess cheat sheet as well as the Apache mod_rewrite docs but additional help would be great.
htaccess rewrite rules can be used to direct requests for one subdirectory to a different location, such as an alternative subdirectory or even the domain root. In this example, requests to http://mydomain.com/folder1/ will be automatically redirected to http://mydomain.com/folder2/.
mod_rewrite lets you create all sorts of rules for manipulating URLs. For example, you can insert values pulled from the requested URL into the new URL, letting you rewrite URLs dynamically.
mod_rewrite is an Apache module that allows for server-side manipulation of requested URLs. mod_rewrite is an Apache module that allows for server-side manipulation of requested URLs. Incoming URLs are checked against a series of rules. The rules contain a regular expression to detect a particular pattern.
htaccess is a plain text configuration file for the Apache HTTP Server that allows administrators to specify options for directories where web content is served. The initial "." in . htaccess means that the file will be invisible on Unix-like systems in directory listings except with the "ls -a" command.
%1
Refers to a pattern matched in a RewriteCond
condition, while $1
refers to a pattern matched inside a RewriteRule
.
More generically, use %n
to refer to the numbered matches from RewriteCond
condition regex patterns, and use $n
to refer to numbered matches from RewriteRule
regex patterns.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With