Welcome to WebmasterWorld Guest from 54.162.96.103

Forum Moderators: Ocean10000 & incrediBILL & phranque

Redirect rules in cPanel / htaccess

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

Preferred Member

10+ Year Member Top Contributors Of The Month

joined:Aug 16, 2004
posts: 354
votes: 1


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?
6:56 pm on Apr 29, 2017 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month

joined:Apr 9, 2011
posts:13677
votes: 440


"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 ::
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members