Forum Moderators: phranque
# Redirect domain.com to domain.com/folder/
RewriteEngine On
RewriteRule ^$ /folder/ [R=301]
# end redirect
the URL's may contain one or m[an]y hyphens, and/or underscores
Since the page URL's have underscores, and or hyphens and they are ranking highly, I do not want to run the ratings, and links to those pages.
RewriteRule ^([\w-]+)\.php http://www.example.com/newdir/$1 [R=301,L]
...
RewriteRule ^(newdir/[^.]+)$ /$1.php [L]
in that order, in the same root-level htaccess file. External redirect to intercept requests for old-style URL and redirect them to new URL; internal rewrite to serve content from new page. In WP, the second rule would not need to exist at all, because WP would take care of it. This may sound good, but the problem is that the first rule might not execute either, thanks to the two different htaccess files, and then where are you? Word Press will not accept a page with a .php extension.
example.com/dark-chocolate.phpwould now be
example.com/wp/dark-chocolate
RewriteRule ^([\w-]+)\.php http://www.example.com/newdir/$1 [R=301,L]
...
RewriteRule ^(newdir/[^.]+)$ /$1.php [L] This is what cPanel wrote in the .htaccess fileOh, great. Now I know for a fact that cPanel is a ### idiot.
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^my\-great\-page\.php$ "https\:\/\/example\.com\/wp\/my\-great\-page" [R=301,L]
Or do I remove the "..."
RewriteCond %{HTTP_HOST} ^.*$#5 if the Condition will always succeed ("host is anything or nothing") and does not involve a capture, it is not needed at all.
RewriteRule ^([\w-]+)\.php /wp/$1 [L]
Note however that you can achieve the same result, without any external redirects, with the single line
RewriteRule ^([\w-]+)\.php /wp/$1 [L] RewriteRule ^([\w-]+)\.php http://www.emperorsherbologist.com/wp/$1 [R=301,L]
RewriteRule ^(newdir/[^.]+)$ /$1.php [L] RewriteEngine On
RewriteCond %{HTTP_HOST} ^.*$ <Files .htaccess>
order allow,deny
deny from all
</Files>
<Limit PUT DELETE>
order deny,allow
deny from all
</Limit>
# Force redirect to https top level
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# End top level redirect
# BEGIN HTTPS Redirection Plugin
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
</IfModule>
# END HTTPS Redirection Plugin
# BEGIN strip out php and then rewrite to /wp/
RewriteEngine On
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^([\w-]+)\.php /wp/$1 [L,R=301]
# END strip out php and then rewrite to /wp/
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /wp/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wp/index.php [L]
</IfModule>
# END WordPress One more question that didn't get answered, unless I overlooked it: Will any of your root-level URLs (example.com/blahblah.php) not get redirected? That potentially includes your own error documents if they happen to end in php.
To clarify the typical WP setup - it is in a real directory or in root, but the .htaccess is in the root
So does that mean I can use
RewriteRule ^([\w-]+)\.php http://example.com/wp/$1 [R=301,L]
If you want to keep the existing URLs, you rewrite using something like this (also before the WP section, but after any 301 redirects you might happen to have): RewriteRule ^([\w-]+)\.php /wp/$1 [L]
Oh, criminy, where did that come from? Get rid of it. If you need to redirect to https, we'll talk about that later.RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
Would I start the command like this?You do not need this condition at all, ever. Maybe cPanel thinks you have multiple domains passing through the same htaccess and the same group of RewriteRules?RewriteEngine On
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^([\w-]+)\.php /wp/$1 [L] Maybe cPanel thinks you have multiple domains passing through the same htaccess and the same group of RewriteRules?
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) [%{HTTP_HOST}%{REQUEST_URI}...] [R=301,L]
My decision is to have the URL's permanently redirected and looking the same as they currently do
RewriteRule ^([\w-]+)\.php http://example.com/wp/$1 [R=301,L] And now for something different
If you need to redirect to https, we'll talk about that later.
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L] Since I have some other domains pointing to example.com will anyone entering those domains get a 404?