Forum Moderators: phranque
The end result of all these modifications results in WP .htaccess code that looks like this:
# BEGIN wordpress
#
RewriteEngine on
#
# Unless you have set a different RewriteBase preceding this point,
# you may delete or comment-out the following RewriteBase directive
# RewriteBase /
#
# if this request is for "/" or has already been rewritten to WP
RewriteCond $1 ^(index\.php)?$ [OR]
# or if request is for image, css, or js file
RewriteCond $1 \.(gif¦jpg¦ico¦css¦js)$ [NC,OR]
# or if URL resolves to existing file
RewriteCond %{REQUEST_FILENAME} -f [OR]
# or if URL resolves to existing directory
RewriteCond %{REQUEST_FILENAME} -d
# then skip the rewrite to WP
RewriteRule ^(.*)$ - [S=1]
# else rewrite the request to WP
RewriteRule . /index.php [L]
#
# END wordpress
[edited by: tedster at 2:52 am (utc) on May 7, 2010]
[edit reason] switch from my-site to example.com - it cannot be owned [/edit]
Good grief! :) Do you really have "index pages" with all of those names?
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule> # Redirect www to bare domain
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} !^example\.com
RewriteRule (.*) http://example.com/$1 [R=301,L] I gave up after half hour or so. It seems quite involved [...] and frankly, I don't want to become an expert in something I may need to deal with only once.
Options +FollowSymLinks -Indexes -MultiViews
RewriteEngine on
#
# If any "example.com" subdomain (or domain) is requested (possibly
# mis-cased or with fully-qualified domain name or appended port number)
RewriteCond %{HTTP_HOST} ^([^.]+\.)*example\.com\.?(:[0-9]+)?$ [NC]
# and if the hostname is not *exactly* the "non-www" canonical hostname
RewriteCond %{HTTP_HOST} !=example.com
# Externally redirect to canonical hostname
RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]
#
# If any "example2.com" subdomain (or domain) is requested
# (possibly mis-cased or with FQDN or appended port number)
RewriteCond %{HTTP_HOST} ^([^.]+\.)*example2\.com\.?(:[0-9]+)?$ [NC]
# and if the requested hostname is not *exactly* the "www" canonical hostname
RewriteCond %{HTTP_HOST} !=www.example2.com
# Externally redirect to canonical hostname
RewriteRule ^(.*)$ http://www.example2.com/$1 [R=301,L]
leaving yourself dependent on others for the security and efficiency of your own server, and unprepared to handle security problems or any other trouble which may arise from changes made to your server configuration by your host or by hackers; Sorry, but that's a poor choice, in my opinion
http://blog.com/hello-world displays correctly. There is no physical file or directory "hello-world" on the host. example.com http://www.example.com/ ~/public_html/index.php example2.com http://www.example2.com/ ~/public_html/index.php www.example.com http://www.example.com/ ~/public_html/index.php example.com/report.pdf http://www.example.com/report.pdf ~/public_html/report.pdf www.example2.com/report.pdf http://www.example2.com/report.pdf ~/public_html/report.pdf example.com/hello-world http://www.example.com/hello-world ~/public_html/index.php?p=1 You'll need two rules only if one domain needs "www" and the other does not. Otherwise, the rule is simply "if requested hostname is not www dot <something> dot com, then externally redirect to add 'www' to the requested hostname."Both domains should always have "www". So you're saying then I need only one rule block. But as described and shown in examples above, I have 2 domains mapping to 1 directory, hence being controlled by 1 htaccess file. Your example has a domain in plaintext in there, so I assume the rule would only apply to that 1 domain. What about the other one? Wouldn't I have to repeat the rule block for the two different domains? Or is there some way to work with placeholders? Or something like "whatever follows, make sure there's always www in the beginning of the line"?
RewriteCond %{HTTP_HOST} ^example.com$
RewriteRule ^(.*)$ "http\:\/\/www\.example\.com$1" [R=301,L] [edited by: Dude_S at 9:20 am (utc) on May 15, 2010]