Forum Moderators: phranque

Message Too Old, No Replies

Redirect rules in cPanel / htaccess

         

lee_sufc

8:30 am on Apr 29, 2017 (gmt 0)

10+ Year Member Top Contributors Of The Month



I currently have a few 301 redirects that I set up via cPanl and and a few I did manually in htaccess. If I delete the redirects from cPanel, will they automatically delete themselves from the htaccess file?

Also...one other question. It appears I have redirects set up in two different ways - which one should I be using:

Redirect 301 /examplepage.php http://www.example.com/blog/examplepagenew/


or this way:

RewriteCond %{HTTP_HOST} ^example\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.example\.com$
RewriteRule ^example\page\.php$ "http\:\/\/www\.example\.com\/New\Example\Page\.php" [R=301,L]


To me, the first way seems so much simpler, but didn't know why or is there was any benefit to the second method?

lucy24

6:56 pm on Apr 29, 2017 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



"Redirect" by that name is a mod_alias directive. RewriteRule is a mod_rewrite directive. You can't have both for the same site. That is, you can--nothing will break--but they won't work as intended, because mod_rewrite executes before mod_alias. It is not in your power to change this.

Yes, redirects using mod_alias are often simpler. But since you can't combine the two, and since some things can only be done in mod_rewrite, you will need to change all mod_alias rules to use mod_rewrite syntax.

If it's just a few, you can do it manually. If there are dozens of them, you can run a few Regular Expressions in a text editor to convert them all globally. (You do this on a copy of your htaccess, of course ;))

Oh, and while you're at it, clean up your RewriteRules. Nothing in the target needs to be escaped. Again, it won't break the Rule, it's just needless clutter. I hope those \ backslashes are posting-typos for / slash, because some of them really will break the rule. They won't crash the server, they'll just prevent it from executing as intended.

:: memo to self: Preview reply, and I won't have to edit three times ::