Welcome to WebmasterWorld Guest from 54.198.210.67

Forum Moderators: Ocean10000 & incrediBILL & phranque

How or Should I Fix generated code

Should I fix what appear to be bad .htaccess con figs generated by cPanel

     
4:39 am on Sep 22, 2017 (gmt 0)

New User from US 

Top Contributors Of The Month

joined:Sept 20, 2017
posts:29
votes: 0


First off, please dumb down any comments. I do not know anything about .htaccess or config mod rewrites what ever. I do learn quickly though. I want to change up my site, meaning move files from one folder to another without screwing up indexed pages or bookmarks. I've built my own site and its on a Hosting server which "shared/bussiness" is the plan, it has a SSL for the main domain. I've moved all pages in the past once, in cPanel with a rewrite tool (which I probably used incorrectly, hence dumb down comments). I had posted the code in a different discussion, and comments made, seemed to make me think it needed to be fixed/cleaned up. From what I can tell the host server will automatically create .htaccess, even if deleted, a new one will appear with the the index config, I think that's it, followed by index.html index.php index."shtml (no idea what this is)" automatically put in the file. And I understand what its talking about using these for the home pages for all directories until it finds one or another .htaccess file in another directory. The only code in the access file is the generated code from using the tool in cPanel to redirect the moved files to their new location, and some GA thing I've never used but did allow or used their guide to in put it in the .htaccess code, don't remember, but did set up. Comment said the code was sloppy and had a lot of unneeded stuff. And another comment said it had cPanel written all over it. I did notice that their wasn't any index config in the file, since the documentation stated it puts it in even if the file is earased, but not in mine.

My question is, should I start from scratch erase all .htaccess code, keeping a back of course, and write it correct, I believe this would be easy for me dumbed down enough, found a lot of info on how and what, just wanted to know if the tool is for people like me who do not know much on the web master side and accessing the website, and can be deleted if correctly fixed, with out messing up any linked sites or indexed page in engines. The info on the hosting server shows how to see the file if hidden and gives some configs for things. But doesn't give support on it just some usually configs. Is it safe to earase theirs code and start from scratch?

RewriteEngine on

RewriteCond %{HTTP_HOST} ^example\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.example\.com$
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^webPages\/choosing_service_why_choose_service\.html$ "http\:\/\/example\.com\/Choosing\-Service\/will_filing_service_in_ohio_help_me\.html" [R=301,L]

The top is repeated for two more pages exactly the same after the rewrite engine on except they all come from the same folder and into their own folder and the file names for the HTML change like above to a degree.

# Google Analytics Integration - Added by cPanel.
<IfModule mod_substitute.c>
AddOutputFilterByType SUBSTITUTE text/html
Substitute "s|(<script type='text/javascript' src='/google_analytics_auto.js'></script>)?</head>|<script src='/google_analytics_auto.js'></script></head>|i"
</IfModule>
# END Google Analytics Integration




Any thoughts would be appreciated.
8:27 am on Sept 22, 2017 (gmt 0)

Senior Member from US 

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

joined:Nov 29, 2005
posts:7877
votes: 547


What are you using to generate your pages?
1:48 pm on Sept 22, 2017 (gmt 0)

New User from US 

Top Contributors Of The Month

joined:Sept 20, 2017
posts:29
votes: 0


I use DW for my editor and ftp, and for helping with some CSS. I hand do all my html, in DW but, type it my self. Plus it's nice to see a decent live version and code split. I know enough about PHP JavaScript, to replace this with mine in examples if this is what you're asking.
DW
the server hosing the sit and I don't know much but I believe it's apache, lynuis (this isn't spelled right)
cPanel I have control of has tools for redirecting. That's the generated code above. I've never put any thing in the .htaccess with anything other than using cPanels tool. It is possible I cut and pasted the GA at the bottom, when setting it up, but not for sure.
5:55 pm on Sept 22, 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:14251
votes: 551


My question is, should I start from scratch erase all .htaccess code, keeping a back of course, and write it correct
Yes.

Well, actually, I was going to say Yes before seeing anything more than the thread subject line :) Of course you should make your own.

I believe it's apache
If you're using htaccess, it's apache. Other server languages (IIS, Nginx) call it by different names and the syntax is entirely different. You don't generally need to know the underlying operating system (Linux, for example).

For some rules, you may need to know exactly which version of Apache your server uses--most likely either 2.2 or 2.4. But 2.4 should be backward-compatible, so existing 2.2 rules will continue to work. (I can't imagine a shared host not installing mod_access_compat with 2.4, or you'd have thousands-to-millions of older sites going up in flames.)
4:05 am on Sept 23, 2017 (gmt 0)

Senior Member from US 

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

joined:Nov 29, 2005
posts:7877
votes: 547


This forum, going back for many years, has many best practice suggestions which provide thought in making decisions.

If you believe there are problems, copy/save the existing htaccess (.htaccess.old) and start with the very minimums needed to set up your site. Then deal with your redirects immediately. If the site has not been up very long, or is not actually earning real income, make all your changes for heirarchy/navigation/folders NOW and forget (plan for, but do not obsess) redirects for what currently exists. The faster you make your permanent long term changes the better off you will be.

DW is an editor known to add bloat to html, though that will not (generally) affect .htaccess. Coding with a text editor that pops up a run window (Notepad ++ for example) will do the same thing without adding ANY code you do not create yourself. HOWEVER, always use what you are most comfortable with, after all, it is your code, your site, your work flow.

cpanel can add a bit more than necessary, thus handcoding .htaccess might give better results. As lucy24 notes, knowing what has been installed at your host is imperative, and having an understanding of what each possible directive does is the other side.

We won't write your .htaccess file for you. Show your best effort (examplified, ie, change any site mentions to example.com) .htaccess for help and observations.
8:54 pm on Sept 23, 2017 (gmt 0)

New User from US 

Top Contributors Of The Month

joined:Sept 20, 2017
posts:29
votes: 0


Well, if this is nasty cPanel generated crap below but wanted to the same result which of the last 2 are right.
This is the documentation on the version of the servers apache
Apache 2.2.24 and 2.2.25
"Apache 2.2.x , (includes mod_rewrite and mod_security) in a SuExec environment"
and this if it matters Linux x86 CentOS 6 (a free version of RedHat) 64-bit Operating System

cPanel code

RewriteEngine on

RewriteCond %{HTTP_HOST} ^example\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.example\.com$
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^webPages\/choosing_service_why_choose_service\.html$ "http\:\/\/example\.com\/Choosing\-Service\/will_filing_service_in_ohio_help_me\.html" [R=301,L]


new way one

RewriteEngine on

RewriteCond %{HTTP_HOST} ^example\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.example\.com$
RewriteRule ^webPages\/choosing_service_why_choose_service\.html$ "https\:\/\/example\.com\/Choosing\-Service\/will_filing_service_in_ohio_help_me\.html" [R=301,L]


new way two

RewriteEngine on

RewriteCond %{HTTP_HOST} ^example\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.example\.com$
RewriteRule ^webPages\/choosing_service_why_choose_service\.html$ "https://www.example.com/Choosing-Service/will_filing_service_in_ohio_help_me.html" [R=301,L]

Are either of these right
11:05 pm on Sept 23, 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:14251
votes: 551


Globally delete ALL of these lines wherever they occur:
RewriteCond %{HTTP_HOST} ^example\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.example\.com$
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
The first two are irrelevant on any single-site htaccess--and even on a multi-site htaccess they're badly worded. The second two are simply not needed. (They're also execrably written. Did somebody at cPanel throw together some code back in 2002, never to be looked at again?)

RewriteRule ^webPages\/choosing_service_why_choose_service\.html$ "https://www.example.com/Choosing-Service/will_filing_service_in_ohio_help_me.html" [R=301,L]
I swear I've said this before. Was it in someone else's thread?
#1 Nothing in the target needs to be escaped (backslash). Ever.
#2 The target does not require quotation marks.
#3 Directory slashes do not need to be escaped in mod_rewrite

Incidentally ... Are these all hard-coded pages, with titles you made up yourself? If so, think about how long a title needs to be; you're not stuck with whatever your CMS generates from a page <title>. I'm especially leery about the combination of
Choosing-Service (Title Case with hyphen)
and
will_filing_service_in_ohio_help_me.html (all lower-case with lowline)
It seems needlessly chaotic.
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members